Content
Matplotlib
In examples below we assume
axsa = fig.add_subplot(111) axim = axsa.imshow(arrwin, interpolation='nearest', origin='bottom', aspect='auto', extent=range)
How to draw axis without labels
import matplotlib.ticker as mtick axsa.xaxis.set_major_formatter( mtick.NullFormatter() )
How to rotate axis labels
for label in axsb.get_xticklabels() : label.set_rotation(60) # rotate by 60 degree label.set_horizontalalignment('center') # 'right', etc.
or use method:
def rotate_lables_for_xaxis(axes, angle=60, alignment='center') : for label in axes.get_xticklabels() : label.set_rotation(angle) label.set_horizontalalignment(alignment)
How to change axis label position on the plot
axsb.xaxis.set_ticks_position('top') axsb.yaxis.set_ticks_position('right')
How to make figure with non-equal subplots
import matplotlib.gridspec as gridspec gs = gridspec.GridSpec(20, 20) # Naive direction [ Y , X ] axsa = fig.add_subplot(gs[ 1:16, 0:14]) axsb = fig.add_subplot(gs[ 1:16, 14:19]) axsc = fig.add_subplot(gs[16: , 0:14])
How to draw a color bar as a separate sub-plot
axCB = fig.add_subplot(gs[ 0, 0:14]) colb = fig.colorbar(axim, cax=axCB, orientation='horizontal') axCB.xaxis.set_ticks_position('top') # change position of axis labels
At the edge of matplotlib and PyQt4
We assume that everything is done in our backend basis:
import matplotlib matplotlib.use('Qt4Agg') import matplotlib.pyplot as plt
How to get the current matplotlib figure window position on monitor
pos = fig.canvas.manager.window.pos() print 'x,y=', pos.x(), pos.y()
How to move the matplotlib figure window in certain (x,y) position
fig.canvas.manager.window.move(x,y) # in pixels from top-left corner
How to move the matplotlib figure window on top (of all pileup windows)
fig.canvas.manager.window.activateWindow() # Makes window active fig.canvas.manager.window.raise_() # Moves window on top
the attribute trick is that the fig.canvas.manager.window
returns the QtGui.QMainWindow
, which is subclass of QtGui.QWidget
with all that useful methods.
How to add figure as a widget of the QtGui
fig = plt.figure(num=None figsize=(5,10), dpi=100, facecolor='w',edgecolor='w',frameon=True) vbox = QtGui.QVBoxLayout() vbox.addWidget(fig.canvas) # Wraps figure canvas in widget self.setLayout(vbox)
How to receive a signal in program when window is activated by the mouse click on frame ?
I do not know yet...
But, if you click on figure canvas (the region inside the window frame, use
fig.canvas.mpl_connect('button_press_event', self.onButtonPressEvent) #Should be implemented something like: def onButtonPressEvent( self, event ): """Figure is picked""" print 'click on fig number =', event.canvas.figure.number
How to receive a signal in program when close window by the click on "X"
fig.canvas.mpl_connect('close_event', self.onCloseEvent) #Should be implemented something like: def onCloseEvent( self, event ): print 'close event, fig number =', event.canvas.figure.number
How to close figure from program call
plt.close( num ) # close figure with known number num ... plt.close('all') # close all figures
Overview
Content Tools