Matplotlib is a plotting library. It relies on some backend to actually render
the plots. The default backend is the agg
backend. This backend only renders
PNGs. On Jupyter notebooks the matplotlib backends are special as they are
rendered to the browser. Generally you will not need to explicitly set the
backend on a Jupyter notebook. This does introduce a discrepancy between code
that runs in Jupyter and code that runs as a script natively in the Python
interpreter. So you need to understand that the 2 environments are not the same
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import gzip | |
def compress_data(data): | |
# Convert to JSON | |
json_data = json.dumps(data, indent=2) | |
# Convert to bytes | |
encoded = json_data.encode('utf-8') | |
# Compress | |
compressed = gzip.compress(encoded) |
Overview: http://matplotlib.org/faq/usage_faq.html#usage
Multiple, manual Axes: https://python4mpia.github.io/plotting/advanced.html
Another intro article http://pbpython.com/effective-matplotlib.html