Label lines in matplotlib.
Project description
matplotlib-label-lines
Easily label line(s) using matplotlib.
The code is heavily based on http://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 binder or use the following script:
import numpy as np
from matplotlib import pyplot as plt
from scipy.stats import loglaplace,chi2
from labellines import labelLine, labelLines
X = np.linspace(0,1,500)
A = [1,2,5,10,20]
funcs = [np.arctan,np.sin,loglaplace(4).pdf,chi2(5).pdf]
plt.subplot(321)
for a in A:
plt.plot(X,np.arctan(a*X),label=str(a))
labelLines(plt.gca().get_lines(),zorder=2.5)
plt.subplot(322)
for a in A:
plt.plot(X,np.sin(a*X),label=str(a))
labelLines(plt.gca().get_lines(),align=False,fontsize=14)
plt.subplot(323)
for a in A:
plt.plot(X,loglaplace(4).pdf(a*X),label=str(a))
xvals = [0.8,0.55,0.22,0.104,0.045]
labelLines(plt.gca().get_lines(),align=False,xvals=xvals,color='k')
plt.subplot(324)
for a in A:
plt.plot(X,chi2(5).pdf(a*X),label=str(a))
lines = plt.gca().get_lines()
l1=lines[-1]
labelLine(l1,0.6,label=r'$Re=${}'.format(l1.get_label()),ha='left',va='bottom',align = False)
labelLines(lines[:-1],align=False)
# labelLines also supports log-scaled x-axes
plt.subplot(325)
for a in A:
plt.semilogx(X,np.arctan(5*a*X),label=str(a))
labelLines(plt.gca().get_lines(),zorder=2.5)
plt.subplot(326)
for a in A:
plt.semilogx(X,chi2(5).pdf(a*X),label=str(a))
labelLines(plt.gca().get_lines(), xvals=(0.1, 1), zorder=2.5)
plt.show()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for matplotlib-label-lines-0.3.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f4f1346f49293a3c34c6e4a50a08c80c81551054ccd85007afb8b85d45407a4 |
|
MD5 | 038a52bfcacc8bca73dbc88a5359409c |
|
BLAKE2b-256 | e825b72ef05113cf1e6dec397a782a0f98ddb7bdedb41a2286b0866afcc0c0e1 |
Close
Hashes for matplotlib_label_lines-0.3.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7e6702f62beae2544c69d4ff6020c6bae7f590b5d9e0f66254a2829fd6c911b |
|
MD5 | 7bc00b42fb456cffb4a14502366fa8d3 |
|
BLAKE2b-256 | 740dd4c84ae9ff80b24c503e2cc5f15f9123d11aea3c7e6a550b938e2d012187 |