Matplotlib axis with two scales shared origin

use the align_yaxis() function: import numpy as np import matplotlib.pyplot as plt def align_yaxis(ax1, v1, ax2, v2): “””adjust ax2 ylimit so that v2 in ax2 is aligned to v1 in ax1″”” _, y1 = ax1.transData.transform((0, v1)) _, y2 = ax2.transData.transform((0, v2)) inv = ax2.transData.inverted() _, dy = inv.transform((0, 0)) – inv.transform((0, y1-y2)) miny, maxy = … Read more

matplotlib python inline on/off

You can switch the matplotlib’s backend by %matplotlib <backend>. To switch back to your system’s default backend use %matplotlib auto or just simply %matplotlib. There are many backends available such as gtk, qt, notebook, etc. I personally highly recommend the notebook (a.k.a. nbagg) backend. It is similar to inline but interactive, allowing zooming/panning from inside … Read more

Matplotlib: Changing the color of an axis

When using figures, you can easily change the spine color with: ax.spines[‘bottom’].set_color(‘#dddddd’) ax.spines[‘top’].set_color(‘#dddddd’) ax.spines[‘right’].set_color(‘red’) ax.spines[‘left’].set_color(‘red’) Use the following to change only the ticks: which=”both” changes both the major and minor tick colors ax.tick_params(axis=”x”, colors=”red”) ax.tick_params(axis=”y”, colors=”red”) And the following to change only the label: ax.yaxis.label.set_color(‘red’) ax.xaxis.label.set_color(‘red’) And finally the title: ax.title.set_color(‘red’)

Calling pylab.savefig without display in ipython

This is a matplotlib question, and you can get around this by using a backend that doesn’t display to the user, e.g. ‘Agg’: import matplotlib matplotlib.use(‘Agg’) import matplotlib.pyplot as plt plt.plot([1,2,3]) plt.savefig(‘/tmp/test.png’) EDIT: If you don’t want to lose the ability to display plots, turn off Interactive Mode, and only call plt.show() when you are … Read more