本文整理汇总了Python中matplotlib.figure.Figure.get_window_extent方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.get_window_extent方法的具体用法?Python Figure.get_window_extent怎么用?Python Figure.get_window_extent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.figure.Figure
的用法示例。
在下文中一共展示了Figure.get_window_extent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Panel_Plotting_Helper
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_window_extent [as 别名]
class Panel_Plotting_Helper(wx.Panel):
def __init__(self, parent):
w, h = parent.GetSize()
wx.Panel.__init__(self, parent=parent, size=(w, 0.7*h), style=wx.SUNKEN_BORDER)
self.parent = parent
self.legends = []
self.legendpos = [0.5, 1]
self.fig = Figure(figsize=(12, 6), dpi=90) # create a figure size 8x6 inches, 80 dots per inches
self.splts = []
self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
self.toolbar = Toolbar(self.canvas) # matplotlib toolbar
# additional toolbar
status_txt = wx.StaticText(self.toolbar, label=' Status on hover: ', pos=(230, 7), \
size=(100, 17))
self.status = wx.TextCtrl(self.toolbar, pos=(330,4), size=(300, 22), \
style=wx.TE_READONLY)
self.toolbar.Realize()
self.figw, self.figh = self.fig.get_window_extent().width, self.fig.get_window_extent().height
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.toolbar, 0, wx.GROW)
sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(sizer)
self.box_width_fraction = 1.0
self.box_height_fraction = 0.9
self.lines = []
self.lined = dict()
self.draggableList = ['Text', 'Legend']
# print(self.toolbar.GetBackgroundColour())
self.fig.canvas.mpl_connect('resize_event', self.squeeze_legend)
self.fig.canvas.mpl_connect('pick_event', self.on_pick)
self.fig.canvas.mpl_connect('motion_notify_event', self.on_motion)
self.fig.canvas.mpl_connect('figure_leave_event', self.on_leave)
def plot_J(self, J, theta, format, r, count):
index = count%3 + 3
self.splts[index].plot(np.arange(len(J)), J, color=format['color'], linewidth=format['linewidth'], linestyle=format['linestyle'], label=format['label'], picker=True)
self.splts[index].set_xlabel("Number of Iteration", fontsize=FONT_SIZE)
self.splts[index].set_ylabel("Cost value", fontsize = FONT_SIZE)
self.set_ticks(self.splts[index], np.arange(len(J)), J)
comment = r + ': [\n'
for t in theta:
comment += ' ' + str(t) + '\n'
comment += ']'
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
annotate = self.splts[index].annotate(comment, xy=(len(J)-1, J[len(J)-1]), xytext=(len(J)/2, (J[0]+J[len(J)-1])/2), \
arrowprops=dict(facecolor='black', shrink=0.05), bbox=props, fontsize=FONT_SIZE, picker=True)
annotate.draggable(True)
def plot_data_gradient_descent(self, X, y, format):
print("Plotting data ...")
for i in range(int(round(len(self.splts)/2))):
self.plot_data(self.splts[i], X, y, format)
self.update_canvas()
def plot_data_minimize_cost_function(self, X, y, format):
print("Plotting data ...")
for i in range(int(round((len(self.splts)+1)/2))):
self.plot_data(self.splts[i], X, y, format)
self.update_canvas()
def plot_data(self, splt, X, y, format):
line, = splt.plot(X, y, 'ro', color=format['color'], label=format['label'], picker=True)
self.set_ticks(splt, X, y)
self.lines.append(line)
splt.set_xlabel("X1", fontsize=FONT_SIZE)
splt.set_ylabel("Y", fontsize=FONT_SIZE)
def set_ticks(self, splt, X, y):
xticks = self.make_ticks(X)
yticks = self.make_ticks(y)
splt.set_xticks(xticks)
splt.set_yticks(yticks)
for tick in splt.get_xticklabels():
tick.set_rotation(45)
tick.set_fontsize(FONT_SIZE)
for tick in splt.get_yticklabels():
tick.set_rotation(45)
tick.set_fontsize(FONT_SIZE)
def plot_all_gradient_descent(self, object):
print("Plotting Linear-Regression (Gradient Descent) and J-Convergence ...")
count = 0
for r in object:
c = self.random_color()
self.splts[count].plot(object[r]['data']['x'], object[r]['data']['y'], color=c, linestyle="-", label="Linear Regression (alpha="+r+")", picker=True)
self.set_ticks(self.splts[count], object[r]['data']['x'], object[r]['data']['y'])
self.plot_J(object[r]['J_history'], object[r]['theta'], {"color": c, "linewidth": 5, "linestyle": "-", "label": "Convergence of J"}, r, count)
count += 1
self.show_legend()
self.update_canvas()
def plot_all_minimize_cost_function(self, object):
print("Plotting Linear-Regression (Normal Equation) ...")
count = 0
for r in object:
#.........这里部分代码省略.........
示例2: BackendMatplotlib
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_window_extent [as 别名]
#.........这里部分代码省略.........
redraw = True
if redraw:
self.draw()
self.ax2.set_yscale('log' if flag else 'linear')
self.ax.set_yscale('log' if flag else 'linear')
def setYAxisInverted(self, flag):
if self.ax.yaxis_inverted() != bool(flag):
self.ax.invert_yaxis()
def isYAxisInverted(self):
return self.ax.yaxis_inverted()
def isKeepDataAspectRatio(self):
return self.ax.get_aspect() in (1.0, 'equal')
def setKeepDataAspectRatio(self, flag):
self.ax.set_aspect(1.0 if flag else 'auto')
self.ax2.set_aspect(1.0 if flag else 'auto')
def setGraphGrid(self, which):
self.ax.grid(False, which='both') # Disable all grid first
if which is not None:
self.ax.grid(True, which=which)
# Data <-> Pixel coordinates conversion
def _mplQtYAxisCoordConversion(self, y):
"""Qt origin (top) to/from matplotlib origin (bottom) conversion.
:rtype: float
"""
height = self.fig.get_window_extent().height
return height - y
def dataToPixel(self, x, y, axis):
ax = self.ax2 if axis == "right" else self.ax
pixels = ax.transData.transform_point((x, y))
xPixel, yPixel = pixels.T
# Convert from matplotlib origin (bottom) to Qt origin (top)
yPixel = self._mplQtYAxisCoordConversion(yPixel)
return xPixel, yPixel
def pixelToData(self, x, y, axis, check):
ax = self.ax2 if axis == "right" else self.ax
# Convert from Qt origin (top) to matplotlib origin (bottom)
y = self._mplQtYAxisCoordConversion(y)
inv = ax.transData.inverted()
x, y = inv.transform_point((x, y))
if check:
xmin, xmax = self.getGraphXLimits()
ymin, ymax = self.getGraphYLimits(axis=axis)
if x > xmax or x < xmin or y > ymax or y < ymin:
return None # (x, y) is out of plot area
return x, y
def getPlotBoundsInPixels(self):