Arrows for matplotlib
Project description
drawarrow
Drawing arrows for matplotlib made easy.
Installation
pip install git+https://github.com/JosephBARBIERDARNAL/drawarrow.git
Quick Start
import matplotlib.pyplot as plt
from drawarrow import fig_arrow
fig, ax = plt.subplots()
ax.scatter(x=[1, 2, 3, 4, 5], y=[1, 2, 3, 4, 5], s=100)
fig_arrow(head_position=(0.5, 0.5), tail_position=(0.2, 0.7), fig=fig, color="r")
plt.show()
Usage guide
drawarrow
provides 2 functions:
fig_arrow()
: draw an arrow on a Matplotlib figure (e.g. the whole chart)ax_arrow()
: draw an arrow on Matplotlib axe (e.g. a subplot)
The difference between mainly lies in their coordinates. An arrow on a Figure would usually be between 0 and 1 for both x and y axis. However, when drawing an arrow on an Axes, it's on the data coordinates.
Those functions have a set a common arguments:
tail_position
: position of the tail of the arrow (on the figure/axes)head_position
: position of the head of the arrow (on the figure/axes)invert
(bool, default to False): whether to invert or not the angle of the arrow (only used ifradius
!=0)radius
(float, default to 0.1):color
: color of the arrow,tail_width
(float, default to 0.5): Width of the tail of the arrowhead_width
(float, default to 4): Head width of the tail of the arrowhead_length
(float, default to 8): Head length of the tail of the arrowlinewidth
(float, default to 0.5): Width of the body of the arrow
ax_arrow()
This function is recommended when what you want to highlight is related to the data itself, such as a specific point in a scatter plot.
Minimalist usage
import matplotlib.pyplot as plt
from drawarrow import ax_arrow
fig, ax = plt.subplots()
ax.scatter(x=[1, 5, 10], y=[5, 12, 3])
ax_arrow((2, 8), (8, 2), ax=ax, color="blue", radius=0.3)
plt.show()
Usage with multiple subplots
import matplotlib.pyplot as plt
from drawarrow import ax_arrow
fig, axs = plt.subplots(ncols=3, nrows=3)
for ax in axs.flat:
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.set_xticks([])
ax.set_yticks([])
ax_arrow((2, 2), (8, 8), ax=ax, color="red", radius=0.4)
plt.show()
fig_arrow()
Minimalist usage
This function is recommended when what you want to highlight something that is more global and not data specific.
import matplotlib.pyplot as plt
from drawarrow import fig_arrow
fig, ax = plt.subplots()
fig_arrow((0.3, 0.3), (0.8, 0.8), fig=fig)
plt.show()
More complex usage
import matplotlib.pyplot as plt
from drawarrow import fig_arrow
fig, ax = plt.subplots()
fig_arrow(
(0.3, 0.3),
(0.8, 0.8),
color="#2a9d8f",
tail_width=2,
head_length=20,
head_width=10,
linewidth=2,
radius=0.7,
invert=True,
fig=fig,
)
plt.show()
Contributions
Contributions (and feedback) are welcome.
TODO features:
- control opacity (alpha parameter in matplotlib)
- draw arrow with an inflection point (see this)
- ...
Installation for contributions
- Fork this repo
git clone https://github.com/yourusername/drawarrow.git
cd drawarrow
pip install -r requirements.txt
pip install -e .
git checkout -b feature-name
- start coding!
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
File details
Details for the file drawarrow-0.0.1.tar.gz
.
File metadata
- Download URL: drawarrow-0.0.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cb0dfbb02af49e92b406af6b5de3dfe2afa3537c3c545236e5f236103df8373 |
|
MD5 | 40284bd95cf3534d34d40f7f3c57a8ca |
|
BLAKE2b-256 | a88f0b82bd731ef9d990cf7e8b9f1e7cddc2cea397500ad3a8e5216571e3599d |
File details
Details for the file drawarrow-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: drawarrow-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e396c93fc863381407b7be3da589d9ed22e8908d89be3f22627a2c1b2c0b60e3 |
|
MD5 | ed2669c4b5f6fd7b112940738723ea5a |
|
BLAKE2b-256 | e8d2d31b4416648264e9861064ec563e67b4a7e4288f83cf4722652be34bb6f6 |