本文整理汇总了Python中matplotlib.figure.Figure.get_dpi方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.get_dpi方法的具体用法?Python Figure.get_dpi怎么用?Python Figure.get_dpi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.figure.Figure
的用法示例。
在下文中一共展示了Figure.get_dpi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [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
示例2: wxMatplotPanelSimple
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [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()
示例3: MatplotlibPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [as 别名]
class MatplotlibPanel(wx.Panel):
def __init__(self,parent,ID=-1,label="",pos=wx.DefaultPosition,size=(100,25)):
self.parent = parent
#(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)
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):
self.parent.parent.panel_enter(event, panel=self.parent)
def callback_leave_axes(self, event):
self.parent.parent.panel_leave(event)
def cla(self):
self.ax.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, I0, I, cmax=None, pois=None):
if I!=None:
if cmax==None:
cmax = I.max()
I[I==0] = np.nan
self.ax.imshow(I, interpolation='nearest', origin='lower', vmin=0, vmax=cmax)
self.ax.contour(I0>0, 1, colors="0.5", linewidths=1)
pyplot.setp(self.ax, xticks=[], yticks=[])
self.ax.set_axis_bgcolor([0.05]*3)
self.ax.axis('image')
if pois!=None:
for i,(x,y) in enumerate(pois):
self.ax.plot(x, y, 'wo', markersize=8)
self.ax.text(x+1, y+1, '%d'%(i+1), bbox=dict(facecolor='w'))
self.canvas.draw()
示例4: myWxPlot
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [as 别名]
class myWxPlot(wx.Panel):
def __init__( self, parent):
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure
self.parent = parent
wx.Panel.__init__( self, parent)
#matplotlib figure
self.figure = Figure( None )
self.figure.set_facecolor( (0.7,0.7,1.) )
self.subplot = self.figure.add_subplot( 111 )
#canvas
self.canvas = FigureCanvasWxAgg( self, -1, self.figure )
self.canvas.SetBackgroundColour( wx.Colour( 100,255,255 ) )
self._SetSize()
self.draw2()
def _SetSize( self ):
size = tuple( self.parent.GetClientSize() )
self.SetSize( size )
self.canvas.SetSize( size )
self.figure.set_size_inches( float( size[0] )/self.figure.get_dpi(),
float( size[1] )/self.figure.get_dpi() )
def draw(self):
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
x = np.arange(-3, 3, 0.25)
y = np.arange(-3, 3, 0.25)
X, Y = np.meshgrid(x, y)
Z = np.sin(X)+ np.cos(Y)
ax = Axes3D(self.figure)
ax.plot_wireframe(X,Y,Z)
def draw2(self):
import numpy as np
theta = np.arange(0,200, 0.1)
x = 2*np.cos(theta/7)
y = 3*np.sin(theta/3)
self.subplot.plot(x,y, '-r')
self.subplot.set_title("Sample", fontsize = 12)
self.subplot.set_xlabel("x")
self.subplot.set_ylabel("y")
self.subplot.set_xlim([-4, 4])
self.subplot.set_ylim([-4, 4])
示例5: MatplotlibPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [as 别名]
class MatplotlibPanel(wx.Panel):
def __init__(self,parent,ID=-1,label="",pos=wx.DefaultPosition,size=(100,25)):
self.parent = parent
#(0) Initialize panel:
wx.Panel.__init__(self,parent,ID,pos,size,wx.STATIC_BORDER,label)
self.SetMinSize(size)
self.parent = parent
#(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)
#self.Bind(wx.EVT_ENTER_WINDOW, self.callback_enter_axes)
self.Bind(wx.EVT_LEAVE_WINDOW, self.callback_leave_axes)
def _create_axes(self):
self.ax = self.figure.add_axes((0,0,1,1), 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):
self.parent.parent.panel_enter(event, panel=self.parent)
def callback_leave_axes(self, event):
self.parent.parent.panel_leave(event)
def cla(self):
self.ax.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, cmax=None):
if I!=None:
if cmax==None:
cmax = I.max()
I[I==0] = np.nan
self.ax.imshow(I, interpolation='nearest', origin='lower', vmin=0, vmax=cmax)
pyplot.setp(self.ax, xticks=[], yticks=[])
self.ax.set_axis_bgcolor([0.05]*3)
self.ax.axis('image')
self.canvas.draw()
示例6: CheckMeansPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [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()
示例7: PlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [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
示例8: PlotPlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [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())
示例9: PlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [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
示例10: __init__
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [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)
示例11: PlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [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
示例12: matplotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [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)
示例13: PlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [as 别名]
class PlotPanel (wx.Panel):
"""
PlotPanel class taken from http://www.scipy.org/Matplotlib_figure_in_a_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 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, parent, **kwargs)
# initialize matplotlib stuff
self.figure = Figure(None, dpi)
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self.SetColor(color)
self._SetSize()
self.draw()
self._resizeflag = 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):
if self._resizeflag:
self._resizeflag = False
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):
# abstract, to be overridden by child classes
raise NotImplementedError(
"Abstract method - must be defined in subclass")
示例14: IdentifyMatplotlibPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [as 别名]
class IdentifyMatplotlibPanel(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()
def _create_axes(self):
self.ax = self.figure.add_axes((0,0,1,1), axisbg=[0.5]*3)
# self.plot(None)
# self.ax.plot( np.random.randn(10) )
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 cla(self):
self.ax.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, cmax=None):
if I!=None:
if cmax==None:
cmax = I.max()
I[I==0] = np.nan
self.ax.imshow(I, interpolation='nearest', origin='lower', vmin=0, vmax=cmax)
pyplot.setp(self.ax, xticks=[], yticks=[])
self.ax.set_axis_bgcolor([0.05]*3)
self.ax.axis('image')
self.canvas.draw()
示例15: WXMatPlotLibPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import get_dpi [as 别名]
class WXMatPlotLibPanel( wx.Panel ):
def __init__( self, parent, color=None, dpi=None, **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( None, dpi )
self.canvas = FigureCanvasWxAgg( self, -1, self.figure )
#self.SetColor( color )
self._SetSize()
self.draw()
self._resizeflag = 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 ):
if self._resizeflag:
self._resizeflag = False
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