printbutton : button for printing a matplotlib plot figure

class tesfdmtools.utils.widgets.printbutton.PrintPlot(canvas, window, text=None, orientation='portrait', fontsize=12, font='Bitstream Vera Sans Mono', parent=None)[source]

Opens a Gtk.PrintOperation widget for sending the given plot and text to the printer.

Needs the debian package gir1.2-poppler-0.18 (or higher version) to be installed.

Args:
  • canvas = the canvas containing the plot

  • window = not used

Kwargs:
  • text = text to be with after the plot (only operational for ‘portrait’ mode)

  • orientation = ‘portrait’ or ‘landscape’

  • fontsize = fontsize (pts) to be used for the text

  • font = fonttype to be used

  • parent = not used

tesfdmtools.utils.widgets.printbutton.printbutton(figure, parent=None, orientation='portrait')[source]

Insert a printbutton in the matplotlib navigation toolbar. Pressing the button opens a printdialog for printing the current figure plot.

Args:
  • figure = the matplotlib figure object

Kwargs:
  • orientation = orientation of the plot. landscape or portrait

Example of use

Below is an example of use from a piece of python code using pyplot:

import numpy

import matplotlib
matplotlib.use('GTK3Agg')

import matplotlib.pyplot as plt              # import plt

from tesfdmtools.utils.widgets.printbutton import printbutton        # import printbutton

fig = plt.figure()                   # initialize matpplotlib figure
ax1 = fig.add_subplot(111)           # define axis

printbutton(fig)                     # insert printbutton in toolbar

x=numpy.arange(100)/100.0*numpy.pi*2.0       # define function
y=numpy.sin(x)

ax1.plot(x,y)                                # plot function
ax1.set_title('test printbutton')
ax1.set_xlabel('X')
ax1.set_ylabel('Y')

fig.caption=['This shows the use of the printbutton',\
             'printbutton is inserted in the toolbar']  # some text which goes with the plot

plt.show()                           # show plot, with printbutton in toolbar
plt.close('all')

The pyplot window will show as follows, with the printbutton inserted in the toolbar

../../_images/printbutton_pyplot.png

The preview of the plot, which is sent to the printer is shown below

../../_images/printbutton_preview.png