Skip to main content

Label lines in matplotlib.

Project description

Copyright (c) 2017 Corentin Cadiou

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Description: # matplotlib-label-lines
[![Build Status](https://travis-ci.org/cphyc/matplotlib-label-lines.svg?branch=master)](https://travis-ci.org/cphyc/matplotlib-label-lines)
[![codecov](https://codecov.io/gh/cphyc/matplotlib-label-lines/branch/master/graph/badge.svg)](https://codecov.io/gh/cphyc/matplotlib-label-lines)
Label line using matplotlib.

From http://stackoverflow.com/questions/16992038/inline-labels-in-matplotlib (original code from NauticalMile).

## Install

Just do:
```bash
pip install matplotlib-label-lines
```
You can try it online on binder [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/cphyc/matplotlib-label-lines/master) or use the following script:
```python
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()
```
![Example](https://raw.githubusercontent.com/cphyc/matplotlib-label-lines/master/example.png)

Platform: UNKNOWN

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matplotlib-label-lines-0.3.5.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matplotlib_label_lines-0.3.5-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file matplotlib-label-lines-0.3.5.tar.gz.

File metadata

  • Download URL: matplotlib-label-lines-0.3.5.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for matplotlib-label-lines-0.3.5.tar.gz
Algorithm Hash digest
SHA256 3b24b36640d032c4210c95db143a6ba5f7486d2e04d1f341beb2a0a7013a3059
MD5 6363b60be31f22dc13177db94b2b6f17
BLAKE2b-256 7be761ac78078734b5a4c7dfab0dace1aacdcf6cb9cad8e1510e06e263881712

See more details on using hashes here.

File details

Details for the file matplotlib_label_lines-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: matplotlib_label_lines-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for matplotlib_label_lines-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3074dffedd7220d2776e665f0989377a4764f4d0116cd90e5748451e863a161b
MD5 409868f00d7da17a9f589ed40e64c8ba
BLAKE2b-256 9f6bf198b4c7ecb99793a9ff762d098d665197ed7013f84152193b559dbffbe3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page