Skip to main content

Save and load matplotlib figures like MATLAB's .fig files!

Project description

mplfig

Matplotlib by default only allows you to export your figures in formats that are used for publishing (e.g., a .pgf file, a resterized .png file, etc.). MATLAB allows you to save files in a .fig format which allows you to change the plot very easily (say, to fix a typo on an axis label, or to change the colorscheme). mplfig strives to bring this functionality to matplotlib. With mplfig, you can save your matplotlib files and load them right back up in another python script.

Example

First, create a figure and save with it mplfig.

import mplfig
import matplotlib.pyplot as plt

xs = list(range(10))
ys = list(map(lambda x: x**2, xs))

plt.plot(xs, ys)
mplfig.save_figure(plt.gcf(), 'myfig.mplpkl')

plt.show()

Before

Next, load it back up and change the figure!

import mplfig
import matplotlib.pyplot as plt

fig = mplfig.load_figure('myfig.mplpkl') # Load the saved figure

axes = fig.get_axes()
axes[0].set_xlabel('$x$') # Add an x label
axes[0].set_ylabel('$y = x^2$') # Add a y label
axes[0].lines[0].set_marker('o') # Add a circle marker

plt.show()

After

Install

mplfig is on PyPI

pip3 install -U mplfig

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mplfig-1.0.1.tar.gz (77.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mplfig-1.0.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file mplfig-1.0.1.tar.gz.

File metadata

  • Download URL: mplfig-1.0.1.tar.gz
  • Upload date:
  • Size: 77.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for mplfig-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6046cf66da2d6064b7ad0567ac0ed4925d310a232bb7d86e11125fded26e86ad
MD5 b25e6f293e2a4f719af113acb28dc224
BLAKE2b-256 a920a397f5216f06d1f8b6020b217747cc11651efdfb9ab5e49d2903db884e18

See more details on using hashes here.

File details

Details for the file mplfig-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mplfig-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for mplfig-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 222af51055337f327c06d7e8bc975f1ec230c7ffe0cc62b7a38b45f06ce3318f
MD5 587fdc5976c652d6c2cb6800fc1602a2
BLAKE2b-256 a4c10423c7954448f2bb582f7f41b528002f1a11d0089d88e01f283cdb19e6a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page