Matplotlib & seaborn tricks

Moved to: Plotting - wiki, this post is no longer updated.

Recently I have been using these package, and found some little tricks. I’ll have to write them down just to save the future me.


Any colormap can be reversed by adding _r after its name, e.g. cmap="RdBu_r" makes the smaller value blue and the bigger value red.

Single plot


Seaborn: sns.someplot(…).set_title("This is a title")


Use plt.axis('equal') before any two-way plot to set the x-axis and y-axis the same scale.

Set label: fig.xlabel(r"Value of $x$")

Plot with subplots


Put this right before or fig.savefig() (credit): fig.tight_layout()


Main title (credit): plt.subplots_adjust(top=0.9); grid.fig.suptitle("This is a big title")

Sub titles: ax[0, 0].set_title('Axis [0, 0]')


Use graph.axes.Axes.set_xlim(left=0) to set only lower limit, and the upper limit would be auto-generated.

Set label: ax[0,0].set_xlabel(r"Value of $x_1$")