Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Label line using matplotlib.

License

NotificationsYou must be signed in to change notification settings

cphyc/matplotlib-label-lines

Repository files navigation

Build statusSupported Python VersionsPyPIcodecov

Easily label line(s) using matplotlib.

The code is heavily based onhttp://stackoverflow.com/questions/16992038/inline-labels-in-matplotlib (original code from NauticalMile).

Install

Just do:

pip install matplotlib-label-lines

You can try it online on binderBinder, get some inspiration fromthe example or from the following script:

importnumpyasnpfrommatplotlibimportpyplotaspltfromscipy.statsimportchi2,loglaplacefromlabellinesimportlabelLine,labelLinesX=np.linspace(0,1,500)A= [1,2,5,10,20]funcs= [np.arctan,np.sin,loglaplace(4).pdf,chi2(5).pdf]fig,axes=plt.subplots(ncols=2,nrows=3,constrained_layout=True,figsize=(8,8))axes=axes.flatten()ax=axes[0]forainA:ax.plot(X,np.arctan(a*X),label=str(a))labelLines(ax.get_lines(),zorder=2.5)ax=axes[1]forainA:ax.plot(X,np.sin(a*X),label=str(a))labelLines(ax.get_lines(),align=False,fontsize=14)ax=axes[2]forainA:ax.plot(X,loglaplace(4).pdf(a*X),label=str(a))xvals= [0.8,0.55,0.22,0.104,0.045]labelLines(ax.get_lines(),align=False,xvals=xvals,color="k")ax=axes[3]forainA:ax.plot(X,chi2(5).pdf(a*X),label=str(a))lines=ax.get_lines()l1=lines[-1]labelLine(l1,0.85,label=r"$Re=${}".format(l1.get_label()),align=False,yoffset=0.01,ha="right",backgroundcolor="none",)labelLines(lines[:-1],xvals=0.85,yoffsets=0.01,align=False,ha="right",backgroundcolor="none")# labelLines also supports log-scaled x-axesax=axes[4]forainA:ax.semilogx(X,np.arctan(5*a*X),label=str(a))labelLines(ax.get_lines(),zorder=2.5)ax=axes[5]forainA:ax.semilogx(X,chi2(5).pdf(a*X),label=str(a))labelLines(ax.get_lines(),xvals=(0.1,1),zorder=2.5)fig.show()

Example

Citing

If you're using this package for research purposes, consider citing theZenodo entry (https://zenodo.org/record/7428071).

About

Label line using matplotlib.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors15


[8]ページ先頭

©2009-2025 Movatter.jp