本文整理汇总了Python中matplotlib.figure.Figure.set_size_inches方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.set_size_inches方法的具体用法?Python Figure.set_size_inches怎么用?Python Figure.set_size_inches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.figure.Figure
的用法示例。
在下文中一共展示了Figure.set_size_inches方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wxMatplotPanelSimple
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
class wxMatplotPanelSimple( wx.Panel ):
def __init__( self, renderPanel, color=None, dpi=None, **kwargs ):
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure
# initialize Panel
if 'id' not in list(kwargs.keys()):
kwargs['id'] = wx.ID_ANY
if 'style' not in list(kwargs.keys()):
kwargs['style'] = wx.NO_FULL_REPAINT_ON_RESIZE
wx.Panel.__init__( self, renderPanel, **kwargs )
self.figure = Figure( None, dpi )
#self.canvas = NoRepaintCanvas( self, -1, self.figure )
self.canvas = FigureCanvasWxAgg( self, -1, self.figure )
sizer = wx.BoxSizer();
sizer.Add( self.canvas, 1, wx.EXPAND )
self.SetSizer( sizer )
self.axes = self.figure.add_subplot( 111 )
self.axes.set_aspect( 'auto' )
self.Bind(wx.EVT_SIZE, self._onSize)
def _onSize( self, event = None ):
pixels = tuple( [ self.GetSize()[0], self.GetSize()[1] ] )
print(pixels)
#if self.canvas.GetMinSize( )[0] != pixels[0] or \
#self.canvas.GetMinSize( )[1] != pixels[1] :
self.canvas.SetMinSize( pixels )
self.figure.set_size_inches( float( pixels[ 0 ] )/self.figure.get_dpi(),
float( pixels[ 1 ] )/self.figure.get_dpi() )
self.canvas.draw()
示例2: save_plotSpectrum
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
def save_plotSpectrum(y,Fs,image_name):
"""
Plots a Single-Sided Amplitude Spectrum of y(t)
"""
fig = Figure(linewidth=0.0)
fig.set_size_inches(fig_width,fig_length, forward=True)
Figure.subplots_adjust(fig, left = fig_left, right = fig_right, bottom = fig_bottom, top = fig_top, hspace = fig_hspace)
n = len(y) # length of the signal
_subplot = fig.add_subplot(2,1,1)
print "Fi"
_subplot.plot(arange(0,n),y)
xlabel('Time')
ylabel('Amplitude')
_subploti_2=fig.add_subplot(2,1,2)
k = arange(n)
T = n/Fs
frq = k/T # two sides frequency range
frq = frq[range(n/2)] # one side frequency range
Y = fft(y)/n # fft computing and normalization
Y = Y[range(n/2)]
_subplot_2.plot(frq,abs(Y),'r') # plotting the spectrum
xlabel('Freq (Hz)')
ylabel('|Y(freq)|')
print "here"
canvas = FigureCanvasAgg(fig)
if '.eps' in outfile_name:
canvas.print_eps(outfile_name, dpi = 110)
if '.png' in outfile_name:
canvas.print_figure(outfile_name, dpi = 110)
示例3: PlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
class PlotPanel(wx.Panel):
"""
The PlotPanel has a Figure and a Canvas. OnSize events simply set a
flag, and the actual resizing of the figure is triggered by an Idle event.
"""
def __init__(self, parent, obj_id):
# initialize Panel
wx.Panel.__init__(self, parent, obj_id)
# initialize matplotlib stuff
self.figure = Figure(None, None)
self.canvas = FigureCanvasWxAgg(self, wx.ID_ANY, self.figure)
rgbtuple = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE).Get()
clr = [c / 255.0 for c in rgbtuple]
self.figure.set_facecolor(clr)
self.figure.set_edgecolor(clr)
self.canvas.SetBackgroundColour(wx.Colour(*rgbtuple))
self.Bind(wx.EVT_SIZE, self._on_size)
def _on_size(self, event):
self._set_size()
def _set_size(self):
pixels = tuple(self.GetClientSize())
self.SetSize(pixels)
self.canvas.SetSize(pixels)
self.figure.set_size_inches(float(pixels[0]) / self.figure.get_dpi(), float(pixels[1]) / self.figure.get_dpi())
def draw(self):
pass # abstract, to be overridden by child classes
示例4: PlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
class PlotPanel (wx.Panel):
"""The PlotPanel has a Figure and a Canvas. OnSize events simply set a
flag, and the actual resizing of the figure is triggered by an Idle event."""
def __init__( self, parent, **kwargs ):
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure
# initialize Panel
if 'id' not in kwargs.keys():
kwargs['id'] = wx.ID_ANY
if 'style' not in kwargs.keys():
kwargs['style'] = wx.NO_FULL_REPAINT_ON_RESIZE
wx.Panel.__init__( self, parent, **kwargs )
# initialize matplotlib stuff
self.figure = Figure()
self.canvas = FigureCanvasWxAgg( self, -1, self.figure )
self._SetSize()
self.draw()
#self.Bind(wx.EVT_IDLE, self._onIdle)
self.Bind(wx.EVT_SIZE, self._onSize)
def _onSize( self, event ):
self._SetSize()
def _SetSize( self ):
pixels = tuple( self.parent.GetClientSize() )
self.SetSize( pixels )
self.canvas.SetSize( pixels )
self.figure.set_size_inches( float( pixels[0] )/self.figure.get_dpi(),
float( pixels[1] )/self.figure.get_dpi() )
def draw(self): pass # abstract, to be overridden by child classes
示例5: MplAxes
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
class MplAxes(object):
def __init__(self, parent):
self._parent = parent
self._parent.resizeEvent = self.resize_graph
self.create_axes()
self.redraw_figure()
def create_axes(self):
self.figure = Figure(None, dpi=100)
self.canvas = FigureCanvas(self.figure)
self.canvas.setParent(self._parent)
axes_layout = QtGui.QVBoxLayout(self._parent)
axes_layout.setContentsMargins(0, 0, 0, 0)
axes_layout.setSpacing(0)
axes_layout.setMargin(0)
axes_layout.addWidget(self.canvas)
self.canvas.setSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
self.canvas.updateGeometry()
self.axes = self.figure.add_subplot(111)
def resize_graph(self, event):
new_size = event.size()
self.figure.set_size_inches([new_size.width() / 100.0, new_size.height() / 100.0])
self.redraw_figure()
def redraw_figure(self):
self.figure.tight_layout(None, 0.8, None, None)
self.canvas.draw()
示例6: PlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
class PlotPanel(wx.Panel):
"""The PlotPanel has a Figure and a Canvas. OnSize events simply set a
flag, and the actual resizing of the figure is triggered by an Idle event."""
def __init__(self, parent, color=None, dpi=None, **kwargs):
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure
self.parent = parent
# initialize Panel
if 'id' not in kwargs.keys():
kwargs['id'] = wx.ID_ANY
if 'style' not in kwargs.keys():
kwargs['style'] = wx.NO_FULL_REPAINT_ON_RESIZE
wx.Panel.__init__(self, parent, **kwargs)
# initialize matplotlib stuff
self.figure = Figure(None, dpi)
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self.SetColor(color)
self._SetSize()
self.initial_draw()
self._resizeflag = False
self._redrawflag = False
self.Bind(wx.EVT_IDLE, self._onIdle)
self.Bind(wx.EVT_SIZE, self._onSize)
def SetColor(self, rgbtuple=None):
"""Set figure and canvas colours to be the same."""
if rgbtuple is None:
rgbtuple = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE).Get()
clr = [c/255. for c in rgbtuple]
self.figure.set_facecolor(clr)
self.figure.set_edgecolor(clr)
self.canvas.SetBackgroundColour(wx.Colour(*rgbtuple))
def _onSize(self, event):
self._resizeflag = True
def _onIdle(self, evt):
with draw_lock:
if self._resizeflag:
self._resizeflag = False
self._SetSize()
if self._redrawflag:
self._redrawflag = False
self.canvas.draw()
def _SetSize(self):
# When drawing from another thread, I think this may need a lock
pixels = tuple(self.parent.GetClientSize())
self.SetSize(pixels)
self.canvas.SetSize(pixels)
self.figure.set_size_inches(float(pixels[0])/self.figure.get_dpi(),
float(pixels[1])/self.figure.get_dpi())
def initial_draw(self): pass # abstract, to be overridden by child classes
示例7: plot_log_well_path
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
def plot_log_well_path(request, object_id) :
run = Run.objects.get(pk=object_id)
data = ToolMWDLog.objects.filter(run=run).order_by('depth')
north = [0,]
east = [0,]
vert = [0,]
for c in range(len(data)-1) :
dv, dn, de = min_curve_delta(data[c].depth,data[c].inclination,data[c].azimuth,
data[c+1].depth, data[c+1].inclination, data[c+1].azimuth)
north.append(dn + north[c])
east.append(de + east[c])
vert.append(dv + vert[c])
fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_axes([0.15, 0.1, 0.8, 0.8])
ax.grid(True)
ax.plot(east, north)
ax.set_title('Well Plot')
ax.set_ylabel('North')
ax.set_xlabel('East')
fig.set_size_inches( (5, 5) )
filename = settings.MEDIA_ROOT + '/images/wellplot.png'
fig.savefig(filename)
return HttpResponseRedirect('/tdsurface/media/images/wellplot.png')
示例8: matplotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
class matplotPanel(wx.Panel):
def __init__(self, drawfunc, parent, id, *args, **kwargs):
super(matplotPanel, self).__init__(parent, id, *args, **kwargs)
self.drawfunc = drawfunc
self.parent = parent
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def _SetSize(self):
# size = tuple(self.parent.GetClientSize())
size = tuple(self.GetClientSize())
# self.SetSize(size)
self.figure = Figure(None)
self.canvas = FigureCanvasWxAgg(self, wx.NewId(), self.figure)
self.canvas.SetSize(size)
dpi = self.figure.get_dpi()
self.figure.set_size_inches(float(size[0]) / dpi, float(size[1]) / dpi)
def OnSize(self, ev):
self.Refresh()
def OnPaint(self, ev):
self._SetSize()
dc = wx.PaintDC(self) # don't delete this line
self.drawfunc(self)
示例9: PlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
class PlotPanel(XmlPanel):
"""Draw a plot (graph)"""
def __init__(self, parent,elem):
XmlPanel.__init__(self, parent)
self.border = True
self.elem = elem
self.figure = Figure()
self.applySize()
self.plot = FigureCanvas(self,-1,self.figure) # FancyText(self,"hi")
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.plot, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizer)
self.Fit()
self.render()
def applySize(self):
size = self.elem.attrib.get("size",None)
if size:
psize = self.parent.GetSize()
try:
size = literal_eval(size)
size = (min(psize[0],size[0]), min(psize[1],size[1])) # graph can't be bigger than the xmlterm
self.SetInitialSize(size)
self.SetSize(size)
dpi = self.figure.get_dpi()
self.figure.set_size_inches(float(size[0])/dpi,float(size[1])/dpi)
# self.plot.SetSize(size)
self.Fit()
except ValueError,e: # size is malformed
print "bad size"
pass
return size
return None
示例10: PlotPlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
class PlotPlotPanel(wx.Panel):
def __init__(self, parent, dpi=None, **kwargs):
wx.Panel.__init__(self, parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, **kwargs)
self.ztv_frame = self.GetTopLevelParent()
self.figure = Figure(dpi=None, figsize=(1.,1.))
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self.Bind(wx.EVT_SIZE, self._onSize)
self.axes_widget = AxesWidget(self.figure.gca())
self.axes_widget.connect_event('motion_notify_event', self.on_motion)
self.plot_point = None
def on_motion(self, evt):
if evt.xdata is not None:
xarg = np.abs(self.ztv_frame.plot_panel.plot_positions - evt.xdata).argmin()
ydata = self.ztv_frame.plot_panel.plot_im_values[xarg]
self.ztv_frame.plot_panel.cursor_position_textctrl.SetValue('{0:.6g},{1:.6g}'.format(evt.xdata, ydata))
if self.plot_point is None:
self.plot_point, = self.axes.plot([evt.xdata], [ydata], 'xm')
else:
self.plot_point.set_data([[evt.xdata], [ydata]])
self.figure.canvas.draw()
def _onSize(self, event):
self._SetSize()
def _SetSize(self):
pixels = tuple(self.GetClientSize())
self.SetSize(pixels)
self.canvas.SetSize(pixels)
self.figure.set_size_inches(float(pixels[0])/self.figure.get_dpi(), float(pixels[1])/self.figure.get_dpi())
示例11: plot_image
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
def plot_image(group):
q = select([log_t.c.query_time, log_t.c.amount_in_queue], log_t.c.id == group_t.c.id)
q = q.where(group_t.c.group_name == group)
q = q.where(log_t.c.query_time >= datetime.now() - timedelta(hours=4))
q = q.order_by(log_t.c.query_time)
thresh = Group.query.filter_by(group_name=group).first().surplus_threshold
data = list(q.execute())
if len(data) < 1:
return redirect(url_for("main_menu"))
png_data = StringIO()
# Zip() with a '*' is a projection, who knew?
time, count = zip(*data)
fig = Figure()
fig.set_size_inches(11, 8.5)
axis = fig.add_subplot(1, 1, 1)
axis.plot(time, count, marker=".")
axis.xaxis.set_major_formatter(DateFormatter("%m/%d %H:%M"))
fig.autofmt_xdate()
axis.axhline(thresh, color="red", linestyle="-.")
canvas = FigureCanvas(fig)
canvas.print_png(png_data)
response = make_response(png_data.getvalue())
response.mimetype = "image/png"
return response
示例12: matplotlib_figure
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
def matplotlib_figure(width, height):
"""Create a Matplotlib figure with specified width and height for rendering.
w
Width of desired plot.
h
Height of desired plot.
return
A Matplotlib figure.
"""
try:
from matplotlib.backends.backend_agg import FigureCanvasAgg
except:
paraview.print_error("Error: Cannot import matplotlib.backends.backend_agg.FigureCanvasAgg")
try:
from matplotlib.figure import Figure
except:
paraview.print_error("Error: Cannot import matplotlib.figure.Figure")
figure = Figure()
figureCanvas = FigureCanvasAgg(figure)
figure.set_dpi(72)
figure.set_size_inches(float(width)/72.0, float(height)/72.0)
return figure
示例13: __init__
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
def __init__(self, figure=None, logger=None, width=500, height=500):
Callback.Callbacks.__init__(self)
if figure is None:
figure = Figure()
dpi = figure.get_dpi()
if dpi is None or dpi < 0.1:
dpi = 100
wd_in, ht_in = float(width)/dpi, float(height)/dpi
figure.set_size_inches(wd_in, ht_in)
self.fig = figure
if hasattr(self.fig, 'set_tight_layout'):
self.fig.set_tight_layout(True)
self.logger = logger
self.fontsize = 10
self.ax = None
self.logx = False
self.logy = False
self.xdata = []
self.ydata = []
# For callbacks
for name in ('draw-canvas', ):
self.enable_callback(name)
示例14: template_plotter
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
def template_plotter(x_axis_label, y_axis_label,x_axes=[],x_ticks=[],title, outfile_name):
fig = Figure(linewidth=0.0)
fig.set_size_inches(fig_width,fig_length, forward=True)
Figure.subplots_adjust(fig, left = fig_left, right = fig_right, bottom = fig_bottom, top = fig_top, hspace = fig_hspace)
_subplot = fig.add_subplot(1,1,1)
_subplot.boxplot(x_axis,notch=0,sym='+',vert=1, whis=1.5)
#_subplot.plot(x,y,color='b', linestyle='--', marker='o' ,label='labels')
a =[i for i in range(1,len(x_ticks)+1)]
_subplot.set_xticklabels(x_ticks)
_subplot.set_xticks(a)
labels=_subplot.get_xticklabels()
for label in labels:
label.set_rotation(30)
_subplot.set_ylabel(y_axis_label,fontsize=36)
_subplot.set_xlabel(x_axis_label)
#_subplot.set_ylim()
#_subplot.set_xlim()
_subplot.set_title(title)
_subplot.legend(loc='upper left',prop=LEGEND_PROP ,bbox_to_anchor=(0.5, -0.05))
canvas = FigureCanvasAgg(fig)
if '.eps' in outfile_name:
canvas.print_eps(outfile_name, dpi = 110)
if '.png' in outfile_name:
canvas.print_figure(outfile_name, dpi = 110)
outfile_name='EpsilonvsMTU.pdf'
if '.pdf' in outfile_name:
canvas.print_figure(outfile_name, dpi = 110)
示例15: plot_standard_curve
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_size_inches [as 别名]
def plot_standard_curve(result, encoding='jpg'):
if not result.isCalibrated:
raise Exception('Can not plot standard curve if experiment is not calibrated.')
fig = Figure()
ax1 = fig.add_subplot(111)
fig.set_size_inches(_plot_size[0],_plot_size[1], forward=True)
fig.set_facecolor(plot_bgcolor)
ax1.set_title('fitted curve')
ax1.grid(True)
background_mean, background_std = result.background_intensity
# avoid division by zero with perfect testing images
if background_mean == 0:
print('warning: background is zero')
background_mean = np.float64(1e-8)
calibX, calibY = result.calibration_data
calibY_snr = calibY / background_mean
calibY_snr_err = result.intensity_stddev[result.calibration_data_indices] / background_mean
curve = fittedCurve(calibX, calibY_snr)
# plot fitted curve
x = np.linspace(0,np.max(calibX),10)
y = map(curve,x)
ax1.plot(x, y, color='black', linewidth=1, label='fitted curve')
# plot calibration points
#ax1.plot(calibX, calibY_snr, marker='x', color='black', linewidth=0) #, yerr=calibY_snr_err)
ax1.errorbar(calibX, calibY_snr, yerr=calibY_snr_err, marker='x', color='black', linewidth=0)
ax1.set_xlabel('concentration [%s]'%_concentration_units)
ax1.set_ylabel('signal / background')
if background_std > 0:
# don't plot lod, and loq if std_dev of background is not known.
# limit of detection
lod = result.limit_of_detection / background_mean
ax1.axhline(y=lod, linewidth=1, color='g', label='LoD', linestyle='--')
# limit of quantification
loq = result.limit_of_quantification / background_mean
ax1.axhline(y=loq, linewidth=1, color='b', label='LoQ', linestyle='-.')
ax1.legend(loc=0)
#plt.margins(0.2)
#fig.subplots_adjust(hspace=0.2, wspace=0.2, bottom=0.15)
#fig.tight_layout()
return fig