https://github.com/paulvirally/mplfig
Save and load matplotlib figures like MATLAB's .fig files!
https://github.com/paulvirally/mplfig
matplotlib matplotlib-figures python python3
Last synced: 10 months ago
JSON representation
Save and load matplotlib figures like MATLAB's .fig files!
- Host: GitHub
- URL: https://github.com/paulvirally/mplfig
- Owner: PaulVirally
- License: mit
- Created: 2022-07-28T15:31:08.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-28T16:31:55.000Z (over 3 years ago)
- Last Synced: 2025-03-19T20:53:18.563Z (10 months ago)
- Topics: matplotlib, matplotlib-figures, python, python3
- Language: Python
- Homepage:
- Size: 488 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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.
```python
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()
```

Next, load it back up and change the figure!
```python
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()
```

Install
=======
mplfig is on PyPI
```sh
pip3 install -U mplfig
```