本文整理汇总了Python中matplotlib.figure.Figure.add_axes方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.add_axes方法的具体用法?Python Figure.add_axes怎么用?Python Figure.add_axes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.figure.Figure
的用法示例。
在下文中一共展示了Figure.add_axes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _figure_default
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
def _figure_default(self):
"""
figure属性的缺省值,直接创建一个Figure对象
"""
figure = Figure()
figure.add_axes([0.05, 0.1, 0.9, 0.85]) #添加绘图区域,四周留有边距
return figure
示例2: plot_LO_horiz_stripes
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
def plot_LO_horiz_stripes():
'''
This uses data that has been processed through pik1 but w/ the hanning filter
disabled s.t. the stripes are more readily apparent.
'''
fig = Figure((10, 4))
canvas = FigureCanvas(fig)
ax = fig.add_axes([0, 0, 1, 1])
ax.axis('off')
plot_radar(ax, 'TOT_stacked_nofilter', 3200, None, [135000, 230000])
xlim = ax.get_xlim()
ylim = ax.get_ylim()
TOT_bounds, VCD_bounds, THW_bounds = find_quiet_regions()
ax.vlines(TOT_bounds[0:2], 0, 3200, colors='red', linewidth=3, linestyles='dashed')
plot_bounding_box(ax, TOT_bounds, '', linewidth=4)
ax.set_xlim(xlim)
ax.set_ylim(ylim)
canvas.print_figure('../FinalReport/figures/TOT_LO_stripes_d.jpg')
zoom_bounds = [5000, 9000, 3000, 3200]
zoom_fig = Figure((2.5, 9))
zoom_canvas = FigureCanvas(zoom_fig)
zoom_ax = zoom_fig.add_axes([0, 0, 1, 1])
zoom_ax.axis('off')
plot_radar(zoom_ax, 'TOT_stacked_nofilter', 3200, zoom_bounds, [135000, 230000])
zoom_canvas.print_figure('../FinalReport/figures/TOT_LO_stripes_zoom.jpg')
示例3: Window
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
class Window():
def __init__(self, master):
self.frame = Tk.Frame(master)
self.f = Figure( figsize=(10, 9), dpi=80 )
self.ax0 = self.f.add_axes( (0.05, .05, .50, .50), axisbg=(.75,.75,.75), frameon=False)
self.ax1 = self.f.add_axes( (0.05, .55, .90, .45), axisbg=(.75,.75,.75), frameon=False)
self.ax2 = self.f.add_axes( (0.55, .05, .50, .50), axisbg=(.75,.75,.75), frameon=False)
self.ax0.set_xlabel( 'Time (s)' )
self.ax0.set_ylabel( 'Frequency (Hz)' )
self.ax0.plot(np.max(np.random.rand(100,10)*10,axis=1),"r-")
self.ax1.plot(np.max(np.random.rand(100,10)*10,axis=1),"g-")
self.ax2.pie(np.random.randn(10)*100)
self.frame = Tk.Frame( root )
self.frame.pack(side=Tk.LEFT, fill=Tk.BOTH, expand=1)
self.canvas = FigureCanvasTkAgg(self.f, master=self.frame)
self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
self.canvas.show()
self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.frame )
self.toolbar.pack()
self.toolbar.update()
示例4: TelescopeEventView
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
class TelescopeEventView(tk.Frame, object):
""" A frame showing the camera view of a single telescope """
def __init__(self, root, telescope, data=None, *args, **kwargs):
self.telescope = telescope
super(TelescopeEventView, self).__init__(root)
self.figure = Figure(figsize=(5, 5), facecolor='none')
self.ax = Axes(self.figure, [0, 0, 1, 1], aspect=1)
self.ax.set_axis_off()
self.figure.add_axes(self.ax)
self.camera_plot = CameraPlot(telescope, self.ax, data, *args, **kwargs)
self.canvas = FigureCanvasTkAgg(self.figure, master=self)
self.canvas.show()
self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
self.canvas._tkcanvas.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
self.canvas._tkcanvas.config(highlightthickness=0)
@property
def data(self):
return self.camera_plot.data
@data.setter
def data(self, value):
self.camera_plot.data = value
self.canvas.draw()
示例5: getImage
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
def getImage(self):
ddict=self.fitresult
try:
fig = Figure(figsize=(6,3)) # in inches
canvas = FigureCanvas(fig)
ax = fig.add_axes([.15, .15, .8, .8])
ax.set_axisbelow(True)
logplot = self.plotDict.get('logy', True)
if logplot:
axplot = ax.semilogy
else:
axplot = ax.plot
axplot(ddict['result']['energy'], ddict['result']['ydata'], 'k', lw=1.5)
axplot(ddict['result']['energy'], ddict['result']['continuum'], 'g', lw=1.5)
legendlist = ['spectrum', 'continuum', 'fit']
axplot(ddict['result']['energy'], ddict['result']['yfit'], 'r', lw=1.5)
fontproperties = FontProperties(size=8)
if ddict['result']['config']['fit']['sumflag']:
axplot(ddict['result']['energy'],
ddict['result']['pileup'] + ddict['result']['continuum'], 'y', lw=1.5)
legendlist.append('pileup')
if matplotlib_version < '0.99.0':
legend = ax.legend(legendlist,0,
prop = fontproperties, labelsep=0.02)
else:
legend = ax.legend(legendlist,0,
prop = fontproperties, labelspacing=0.02)
except ValueError:
fig = Figure(figsize=(6,3)) # in inches
canvas = FigureCanvas(fig)
ax = fig.add_axes([.15, .15, .8, .8])
ax.set_axisbelow(True)
ax.plot(ddict['result']['energy'], ddict['result']['ydata'], 'k', lw=1.5)
ax.plot(ddict['result']['energy'], ddict['result']['continuum'], 'g', lw=1.5)
legendlist = ['spectrum', 'continuum', 'fit']
ax.plot(ddict['result']['energy'], ddict['result']['yfit'], 'r', lw=1.5)
fontproperties = FontProperties(size=8)
if ddict['result']['config']['fit']['sumflag']:
ax.plot(ddict['result']['energy'],
ddict['result']['pileup'] + ddict['result']['continuum'], 'y', lw=1.5)
legendlist.append('pileup')
if matplotlib_version < '0.99.0':
legend = ax.legend(legendlist,0,
prop = fontproperties, labelsep=0.02)
else:
legend = ax.legend(legendlist,0,
prop = fontproperties, labelspacing=0.02)
ax.set_xlabel('Energy')
ax.set_ylabel('Counts')
legend.draw_frame(False)
outfile = self.outdir+"/"+self.outfile+".png"
try:
os.remove(outfile)
except:
pass
canvas.print_figure(outfile)
return self.__getFitImage(self.outfile+".png")
示例6: MyMplCanvas
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
class MyMplCanvas(FigureCanvas):
"""Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
def __init__(self, parent=None, width=5, height=4, dpi=100):
self.fig1 = Figure(figsize=(width, height), dpi=dpi)
self.fig2 = Figure(figsize=(width, height), dpi=dpi)
fig3 = Figure(figsize=(width, height), dpi=dpi)
self.axes1 = self.fig1.add_subplot(223)
print self.axes1.__class__.__name__
self.axes2 = self.fig2.add_subplot(221)
# We want the axes cleared every time plot() is called
#self.axes.hold(False)
#self.axes2.hold(False)
self.compute_initial_figure()
#
FigureCanvas.__init__(self, self.fig1)
self.setParent(parent)
FigureCanvas.setSizePolicy(self,
QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
t = arange(0.0, 1.0, 0.01)
s = sin(2*pi*t)
axes3 = fig3.add_subplot(1, 2, 2)
axes3.plot(t,s)
axes3.set_figure(self.fig1)
self.fig1.add_axes(axes3)
def compute_initial_figure(self):
pass
示例7: Canvas
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
class Canvas(FigureCanvas):
def __init__(self,parent,dpi=300.0):
size = parent.size()
self.dpi = dpi
self.width = size.width() / dpi
self.height = size.height() / dpi
self.figure = Figure(figsize=(self.width, self.height), dpi=self.dpi, facecolor='white', edgecolor='k', frameon=True)
self.figure.subplots_adjust(left=0.00, bottom=0.00, right=1, top=1, wspace=None, hspace=None)
# left, bottom, width, height
self.axes = self.figure.add_axes([0.10,0.15,0.80,0.80])
self.axes.set_xticks([])
self.axes.set_yticks([])
self.axes.set_axis_off()
self.axcb = self.figure.add_axes([0.1, 0.05, 0.8, 0.05])
self.axcb.set_xticks([])
self.axcb.set_yticks([])
FigureCanvas.__init__(self, self.figure)
self.updateGeometry()
self.draw()
self.setParent(parent)
def on_pre_draw(self):
pass
def on_draw(self):
raise NotImplementedError
def on_post_draw(self):
sleep(0.005)
def redraw(self):
self.on_pre_draw()
self.on_draw()
self.on_post_draw()
示例8: PlotFigure
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
class PlotFigure(Frame):
def __init__(self):
Frame.__init__(self, None, -1, "Test embedded wxFigure")
self.fig = Figure((5,4), 75)
self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
# On Windows, default frame size behaviour is incorrect
# you don't need this under Linux
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
self.toolbar.SetSize(Size(fw, th))
# Create a figure manager to manage things
# Now put all into a sizer
sizer = BoxSizer(VERTICAL)
# This way of adding to sizer allows resizing
sizer.Add(self.canvas, 1, LEFT|TOP|GROW)
# Best to allow the toolbar to resize!
sizer.Add(self.toolbar, 0, GROW)
self.SetSizer(sizer)
self.Fit()
EVT_TIMER(self, TIMER_ID, self.onTimer)
def init_plot_data(self):
# jdh you can add a subplot directly from the fig rather than
# the fig manager
a = self.fig.add_axes([0.075,0.1,0.75,0.85])
cax = self.fig.add_axes([0.85,0.1,0.075,0.85])
self.x = npy.empty((120,120))
self.x.flat = npy.arange(120.0)*2*npy.pi/120.0
self.y = npy.empty((120,120))
self.y.flat = npy.arange(120.0)*2*npy.pi/100.0
self.y = npy.transpose(self.y)
z = npy.sin(self.x) + npy.cos(self.y)
self.im = a.imshow( z, cmap=cm.jet)#, interpolation='nearest')
self.fig.colorbar(self.im,cax=cax,orientation='vertical')
def GetToolBar(self):
# You will need to override GetToolBar if you are using an
# unmanaged toolbar in your frame
return self.toolbar
def onTimer(self, evt):
self.x += npy.pi/15
self.y += npy.pi/20
z = npy.sin(self.x) + npy.cos(self.y)
self.im.set_array(z)
self.canvas.draw()
#self.canvas.gui_repaint() # jdh wxagg_draw calls this already
def onEraseBackground(self, evt):
# this is supposed to prevent redraw flicker on some X servers...
pass
示例9: _figure_default
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
def _figure_default(self):
'''
set the defaults for the figure
'''
figure = Figure()
figure.add_axes([0.05, 0.04, 0.9, 0.92])
figure.axes[0].get_xaxis().set_ticks([])
figure.axes[0].get_yaxis().set_ticks([])
return figure
示例10: time_basic_plot
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
def time_basic_plot():
fig = Figure()
canvas = FigureCanvas(fig)
ax = WCSAxes(fig, [0.15, 0.15, 0.7, 0.7], wcs=MSX_WCS)
fig.add_axes(ax)
ax.set_xlim(-0.5, 148.5)
ax.set_ylim(-0.5, 148.5)
canvas.draw()
示例11: __init__
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
def __init__(self, parent=None):
fig = Figure()
super(ImageCanvas, self).__init__(fig)
matplotlib.rcParams.update({'font.size': 10})
# Generate axes on the figure
self.axes_err = fig.add_axes([0.075, 0.05, 0.775, 0.1], facecolor='k') # error plot
self.axes_ftt = fig.add_axes([0.075, 0.175, 0.775, 0.675], frame_on=True) # FTT image frame
self.axes_vsum = fig.add_axes([0.075, 0.875, 0.775, 0.1], facecolor='k') # vertical summaiton
self.axes_hsum = fig.add_axes([0.875, 0.175, 0.1, 0.675], facecolor='k') # horizontal summation
# The image, plot random data for initialization
self.ftt_image = self.axes_ftt.imshow(np.random.rand(512,512),
cmap='gray',
interpolation='none',
extent=(1,512, 512,1),
norm=LogNorm(vmin=0.001, vmax=1)
)
self.axes_ftt.set_axis_off()
self.axes_ftt.set_aspect('auto')
# Summation plots, generate axes and plot random data for initialization
self.xlims = np.linspace(0, 511, 512)
self.ylims = np.linspace(0, 511, 512)
self.errlims = np.linspace(0, 99, 100)
self.axes_vsum.relim()
self.axes_vsum.autoscale_view()
self.axes_hsum.relim()
self.axes_hsum.autoscale_view()
self.axes_err.relim()
self.axes_err.autoscale_view()
# error buffer
self.errs = np.zeros((100,2))
self.vsum_lines, = self.axes_vsum.plot(self.ylims, np.random.rand(512,1), color='w', linewidth=0.5)
self.hsum_lines, = self.axes_hsum.plot(np.random.rand(512,1), self.xlims, color='w', linewidth=0.5)
self.xerr_lines, = self.axes_err.plot(self.errlims, self.errs[:,0], color='r')
self.yerr_lines, = self.axes_err.plot(self.errlims, self.errs[:,1], color='y')
# Initialize fiber marker list and add to axes
self.marker_lines = []
ratio = (512/12.0, 512/12.0)
x = np.array([[-ratio[0]*1.5, -ratio[0]*0.5], [ratio[0]*0.5, ratio[0]*1.5], [0.0, 0.0], [0.0, 0.0]]) + fiber_loc[0]
y = np.array([[0.0, 0.0], [0.0, 0.0], [-ratio[1]*1.5, -ratio[1]*0.5], [ratio[1]*0.5, ratio[1]*1.5]]) + fiber_loc[1]
for ind in range(len(x)):
self.marker_lines.append(mlines.Line2D(x[ind], y[ind], color='g', linewidth=2.0)) #.set_data(x[ind], y[ind])
for line in self.marker_lines:
self.axes_ftt.add_line(line)
cid = self.mpl_connect('button_press_event', self.on_press)
示例12: time_basic_plot
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
def time_basic_plot(self):
fig = Figure()
canvas = FigureCanvas(fig)
ax = WCSAxes(fig, [0.15, 0.15, 0.7, 0.7],
wcs=WCS(self.msx_header))
fig.add_axes(ax)
ax.set_xlim(-0.5, 148.5)
ax.set_ylim(-0.5, 148.5)
canvas.draw()
示例13: plot_quiet_regions
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
def plot_quiet_regions():
# Plot the region that the noise was calculated from...
# For TOT...
TOT_bounds, VCD_bounds, THW_bounds = find_quiet_regions()
# TOT/JKB2d/X16a gives:
# mag = 32809.224658469, phs = -0.90421798501485484
# VCD/JKB2g/DVD01a gives:
# mag = 15720.217174332585, phs = -0.98350090576267946
# THW/SJB2/DRP02a gives:
# 26158.900202734963, phs = 1.6808311318828895
TOT_fig = Figure((10, 8))
TOT_canvas = FigureCanvas(TOT_fig)
TOT_ax = TOT_fig.add_axes([0, 0, 1, 1])
TOT_ax.axis('off')
plot_radar(TOT_ax, 'TOT_LO', 3200, None, [135000, 234000])
xlim = TOT_ax.get_xlim()
ylim = TOT_ax.get_ylim()
TOT_ax.vlines(TOT_bounds[0:2], 0, 3200, colors='red', linewidth=3, linestyles='dashed')
plot_bounding_box(TOT_ax, TOT_bounds, '', linewidth=4)
TOT_ax.set_xlim(xlim)
TOT_ax.set_ylim(ylim)
TOT_canvas.print_figure('../FinalReport/figures/TOT_quiet_region.jpg')
VCD_fig = Figure((10, 8))
VCD_canvas = FigureCanvas(VCD_fig)
VCD_ax = VCD_fig.add_axes([0, 0, 1, 1])
VCD_ax.axis('off')
plot_radar(VCD_ax, 'VCD_LO', 3200, None, [135000, 234000])
xlim = VCD_ax.get_xlim()
ylim = VCD_ax.get_ylim()
VCD_ax.vlines(VCD_bounds[0:2], 0, 3200, colors='red', linewidth=3, linestyles='dashed')
plot_bounding_box(VCD_ax, VCD_bounds, '', linewidth=4)
VCD_ax.set_xlim(xlim)
VCD_ax.set_ylim(ylim)
VCD_canvas.print_figure('../FinalReport/figures/VCD_quiet_region.jpg')
THW_fig = Figure((10, 8))
THW_canvas = FigureCanvas(THW_fig)
THW_ax = THW_fig.add_axes([0, 0, 1, 1])
THW_ax.axis('off')
plot_radar(THW_ax, 'THW_LO', 3200, None, [135000, 234000])
xlim = THW_ax.get_xlim()
ylim = THW_ax.get_ylim()
THW_ax.vlines(THW_bounds[0:2], 0, 3200, colors='red', linewidth=3, linestyles='dashed')
plot_bounding_box(THW_ax, THW_bounds, '', linewidth=4)
THW_ax.set_xlim(xlim)
THW_ax.set_ylim(ylim)
THW_canvas.print_figure('../FinalReport/figures/THW_quiet_region.jpg')
示例14: time_basic_plot_with_grid
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
def time_basic_plot_with_grid():
fig = Figure()
canvas = FigureCanvas(fig)
ax = WCSAxes(fig, [0.15, 0.15, 0.7, 0.7], wcs=MSX_WCS)
fig.add_axes(ax)
ax.grid(color='red', alpha=0.5, linestyle='solid')
ax.set_xlim(-0.5, 148.5)
ax.set_ylim(-0.5, 148.5)
canvas.draw()
示例15: CheckMeansPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_axes [as 别名]
class CheckMeansPanel(wx.Panel):
def __init__(self,parent,ID=-1,label="",pos=wx.DefaultPosition,size=(100,25)):
#(0) Initialize panel:
wx.Panel.__init__(self,parent,ID,pos,size,wx.STATIC_BORDER,label)
self.SetMinSize(size)
#(1) Create Matplotlib figure:
self.figure = Figure(facecolor=(0.8,)*3)
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self._resize()
self._create_axes()
# self.cidAxisEnter = self.canvas.mpl_connect('axes_enter_event', self.callback_enter_axes)
# self.cidAxisLeave = self.canvas.mpl_connect('axes_leave_event', self.callback_leave_axes)
def _create_axes(self):
self.ax = self.figure.add_axes((0,0,1,1), axisbg=[0.5]*3)
self.cax = self.figure.add_axes((0.1,0.05,0.8,0.02), axisbg=[0.5]*3)
pyplot.setp(self.ax, xticks=[], yticks=[])
def _resize(self):
szPixels = tuple( self.GetClientSize() )
self.canvas.SetSize(szPixels)
szInches = float(szPixels[0])/self.figure.get_dpi() , float(szPixels[1])/self.figure.get_dpi()
self.figure.set_size_inches( szInches[0] , szInches[1] )
# def callback_enter_axes(self, event):
# print 'buta-san in'
# def callback_leave_axes(self, event):
# print 'buta-san out'
def cla(self):
self.ax.cla()
self.cax.cla()
# self.ax.set_position([0,0,1,1])
self.ax.set_axis_bgcolor([0.5]*3)
pyplot.setp(self.ax, xticks=[], yticks=[], xlim=(0,1), ylim=(0,1))
self.ax.axis('tight')
self.canvas.draw()
def plot(self, I):
I = np.asarray(I, dtype=float)
I[I==0] = np.nan
self.ax.imshow(I, interpolation='nearest', origin='lower')
pyplot.setp(self.ax, xticks=[], yticks=[])
self.ax.set_axis_bgcolor([0.05]*3)
self.ax.axis('image')
cb = pyplot.colorbar(cax=self.cax, mappable=self.ax.images[0], orientation='horizontal')
pyplot.setp(cb.ax.get_xticklabels(), color='0.5')
self.canvas.draw()