matplotlib

A 2-post collection

Jupyter matplotlib auto inline

You might need to use this magic:

%matplotlib inline

Every time you want to force the inline output for a graph figure generated from matplotlib, which is actually most of the times.

There is a way to make this "automatic" by configuring the file .jupyter/jupyter_notebook_config.py:

By adding:

c.InteractiveShellApp.matplotlib = "inline"  

And just reload the notebook in your browser, this should work automatically without the explicit magic anymore.

อ่านต่อ »

Matplotlib Set Figure Size

import matplotlib.pylot as plt  
fig, axes = plt.subplots(...)  
# ndarray size [w, h] in inches
# with default DPI set to 100
size = fig.get_size_inches() * 2  
fig.set_size_inches(size[0], size[1])  

The code snippet above set the figure size to be 4 times as large as the default 8 x 6 sq.inches, while keeping DPI to stay the same this will make things appear to be smaller.

อ่านต่อ »