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.
Last updated: 20200524-1500 CEST
Set label:
Sub titles:
Set label:
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.
Last updated: 20200524-1500 CEST
General
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
Title
Seaborn:sns.someplot(…).set_title("This is a title")
Axis
Useplt.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
Sizing
Put this right beforeplt.show()
or fig.savefig()
(credit): fig.tight_layout()
Title
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]')
Axis
Usegraph.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$")
评论
发表评论