2012-12-30 18:17:41 +00:00
|
|
|
Exporting
|
|
|
|
=========
|
|
|
|
|
|
|
|
PyQtGraph provides a variety of export formats for all 2D graphics. For 3D graphics, see `Exporting 3D Graphics`_ below.
|
|
|
|
|
|
|
|
Exporting from the GUI
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
Any 2D graphics can be exported by right-clicking on the graphic, then selecting 'export' from the context menu.
|
|
|
|
This will display the export dialog in which the user must:
|
|
|
|
|
|
|
|
#. Select an item (or the entire scene) to export. Selecting an item will cause the item to be hilighted in the original
|
|
|
|
graphic window (but this hilight will not be displayed in the exported file).
|
|
|
|
#. Select an export format.
|
|
|
|
#. Change any desired export options.
|
|
|
|
#. Click the 'export' button.
|
|
|
|
|
|
|
|
Export Formats
|
|
|
|
--------------
|
|
|
|
|
|
|
|
* Image - PNG is the default format. The exact set of image formats supported will depend on your Qt libraries. However,
|
|
|
|
common formats such as PNG, JPG, and TIFF are almost always available.
|
|
|
|
* SVG - Graphics exported as SVG are targeted to work as well as possible with both Inkscape and
|
|
|
|
Adobe Illustrator. For high quality SVG export, please use PyQtGraph version 0.9.3 or later.
|
|
|
|
This is the preferred method for generating publication graphics from PyQtGraph.
|
|
|
|
* CSV - Exports plotted data as CSV. This exporter _only_ works if a PlotItem is selected for export.
|
|
|
|
* Matplotlib - This exporter opens a new window and attempts to re-plot the
|
|
|
|
data using matplotlib (if available). Note that some graphic features are either not implemented
|
|
|
|
for this exporter or not available in matplotlib. This exporter _only_ works if a PlotItem is selected
|
|
|
|
for export.
|
|
|
|
* Printer - Exports to the operating system's printing service. This exporter is provided for completeness,
|
|
|
|
but is not well supported due to problems with Qt's printing system.
|
2019-11-12 17:01:49 +00:00
|
|
|
* HDF5 - Exports data from a :class:`~pyqtgraph.PlotItem` to a HDF5 file if
|
|
|
|
h5py_ is installed. This exporter supports :class:`~pyqtgraph.PlotItem`
|
|
|
|
objects containing multiple curves, stacking the data into a single HDF5
|
|
|
|
dataset based on the ``columnMode`` parameter. If data items aren't the same
|
|
|
|
size, each one is given its own dataset.
|
2012-12-30 18:17:41 +00:00
|
|
|
|
2019-11-12 17:01:49 +00:00
|
|
|
.. _h5py: https://www.h5py.org/
|
2012-12-30 18:17:41 +00:00
|
|
|
|
|
|
|
Exporting from the API
|
|
|
|
----------------------
|
|
|
|
|
2021-05-07 06:20:21 +00:00
|
|
|
To export a file programatically, follow this example:
|
2012-12-30 18:17:41 +00:00
|
|
|
|
2021-05-07 06:20:21 +00:00
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
import pyqtgraph as pg
|
|
|
|
import pyqtgraph.exporters
|
2012-12-30 18:17:41 +00:00
|
|
|
|
2021-05-07 06:20:21 +00:00
|
|
|
# generate something to export
|
|
|
|
plt = pg.plot([1,5,2,4,3])
|
2012-12-30 18:17:41 +00:00
|
|
|
|
2021-05-07 06:20:21 +00:00
|
|
|
# create an exporter instance, as an argument give it
|
|
|
|
# the item you wish to export
|
|
|
|
exporter = pg.exporters.ImageExporter(plt.plotItem)
|
2012-12-30 18:17:41 +00:00
|
|
|
|
2021-05-07 06:20:21 +00:00
|
|
|
# set export parameters if needed
|
|
|
|
exporter.parameters()['width'] = 100 # (note this also affects height parameter)
|
2012-12-30 18:17:41 +00:00
|
|
|
|
2021-05-07 06:20:21 +00:00
|
|
|
# save to file
|
|
|
|
exporter.export('fileName.png')
|
|
|
|
|
|
|
|
To export the overall layout of a GraphicsLayoutWidget `grl`, the exporter initialization is
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
exporter = pg.exporters.ImageExporter( grl.scene() )
|
|
|
|
|
|
|
|
instead.
|
2012-12-30 18:17:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
Exporting 3D Graphics
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
The exporting functionality described above is not yet available for 3D graphics. However, it is possible to
|
|
|
|
generate an image from a GLViewWidget by using QGLWidget.grabFrameBuffer or QGLWidget.renderPixmap::
|
|
|
|
|
|
|
|
glview.grabFrameBuffer().save('fileName.png')
|
|
|
|
|
|
|
|
See the Qt documentation for more information.
|