Skip to content

Commit 054046c

Browse files
committed
Add new example with advanced MarkerStyle mapping
1 parent d8cf954 commit 054046c

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
==============================================
3+
Mapping marker properties to multivariate data
4+
==============================================
5+
6+
This example shows how to use different properties of markers to plot
7+
multivariate datasets. Following example shows an illustrative case of
8+
plotting success of baseball throw as an smiley face with size mapped to
9+
the skill of thrower, rotation mapped to the take-off angle, and thrust
10+
to the color of the marker.
11+
"""
12+
13+
import numpy as np
14+
import matplotlib.pyplot as plt
15+
from matplotlib.markers import MarkerStyle
16+
from matplotlib.transforms import Affine2D
17+
from matplotlib.textpath import TextPath
18+
from matplotlib.colors import Normalize
19+
20+
SUCCESS_SYMBOLS = [
21+
TextPath((0,0), "☹"),
22+
TextPath((0,0), "😒"),
23+
TextPath((0,0), "☺"),
24+
]
25+
26+
N = 25
27+
np.random.seed(42)
28+
skills = np.random.uniform(5, 80, size=N) * 0.1 + 5
29+
takeoff_angles = np.random.normal(0, 90, N)
30+
thrusts = np.random.uniform(size=N)
31+
successfull = np.random.randint(0, 3, size=N)
32+
positions = np.random.normal(size=(N, 2)) * 5
33+
data = zip(skills, takeoff_angles, thrusts, successfull, positions)
34+
35+
cmap = plt.cm.get_cmap("plasma")
36+
fig, ax = plt.subplots()
37+
fig.suptitle("Throwing success", size=14)
38+
for skill, takeoff, thrust, mood, pos in data:
39+
t = Affine2D().scale(skill).rotate_deg(takeoff)
40+
m = MarkerStyle(SUCCESS_SYMBOLS[mood], transform=t)
41+
ax.plot(pos[0], pos[1], marker=m, color=cmap(thrust))
42+
fig.colorbar(plt.cm.ScalarMappable(norm=Normalize(0, 1), cmap=cmap),
43+
ax=ax, label="Normalized Thrust [a.u.]")
44+
ax.set_xlabel("X position [m]")
45+
ax.set_ylabel("Y position [m]")

lib/matplotlib/markers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
9494
* :doc:`/gallery/lines_bars_and_markers/marker_reference`
9595
* :doc:`/gallery/lines_bars_and_markers/scatter_star_poly`
96-
96+
* :doc:`/gallery/lines_bars_and_markers/multivariate_marker_plot`
9797
9898
.. |m00| image:: /_static/markers/m00.png
9999
.. |m01| image:: /_static/markers/m01.png

0 commit comments

Comments
 (0)