Skip to content

Rework example "Scatter Star Poly" to "Marker examples" #16102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/lines_bars_and_markers/marker_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
:doc:`/gallery/shapes_and_collections/marker_path`.

For a list of all markers see also the `matplotlib.markers` documentation.

For example usages see
:doc:`/gallery/lines_bars_and_markers/scatter_star_poly`.
"""

import matplotlib.pyplot as plt
Expand Down
44 changes: 26 additions & 18 deletions examples/lines_bars_and_markers/scatter_star_poly.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
"""
=================
Scatter Star Poly
=================
===============
Marker examples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of this title: it doesn't summarizes what the example showcases in particular compared to all of the other examples on markers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it's not very instructive. But I didn't find a better name. OTOH, the example itself doesn't add much compared to the maker reference and module docs. I was about to delete it but decided to keep it as a usage example.

If you can think of a better name, proposals are always welcome.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be in favor of removing it :)

===============

Create multiple scatter plots with different
star symbols.
Example with different ways to specify markers.

For a list of all markers see also the `matplotlib.markers` documentation.
"""
import numpy as np
import matplotlib.pyplot as plt

# Fixing random state for reproducibility
np.random.seed(19680801)


x = np.random.rand(10)
y = np.random.rand(10)
z = np.sqrt(x**2 + y**2)

plt.subplot(321)
plt.scatter(x, y, s=80, c=z, marker=">")
fig, axs = plt.subplots(2, 3, sharex=True, sharey=True)

# marker symbol
axs[0, 0].scatter(x, y, s=80, c=z, marker=">")
axs[0, 0].set_title("marker='>'")

plt.subplot(322)
plt.scatter(x, y, s=80, c=z, marker=(5, 0))
# marker from TeX
axs[0, 1].scatter(x, y, s=80, c=z, marker=r'$\alpha$')
axs[0, 1].set_title(r"marker=r'\$\alpha\$'")

# marker from path
verts = np.array([[-1, -1], [1, -1], [1, 1], [-1, -1]])
plt.subplot(323)
plt.scatter(x, y, s=80, c=z, marker=verts)
axs[0, 2].scatter(x, y, s=80, c=z, marker=verts)
axs[0, 2].set_title("marker=verts")

plt.subplot(324)
plt.scatter(x, y, s=80, c=z, marker=(5, 1))
# regular polygon marker
axs[1, 0].scatter(x, y, s=80, c=z, marker=(5, 0))
axs[1, 0].set_title("marker=(5, 0)")

plt.subplot(325)
plt.scatter(x, y, s=80, c=z, marker='+')
# regular star marker
axs[1, 1].scatter(x, y, s=80, c=z, marker=(5, 1))
axs[1, 1].set_title("marker=(5, 1)")

plt.subplot(326)
plt.scatter(x, y, s=80, c=z, marker=(5, 2))
# regular asterisk marker
axs[1, 2].scatter(x, y, s=80, c=z, marker=(5, 2))
axs[1, 2].set_title("marker=(5, 2)")

plt.tight_layout()
plt.show()
1 change: 1 addition & 0 deletions lib/matplotlib/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@

* :doc:`/gallery/lines_bars_and_markers/marker_reference`
* :doc:`/gallery/shapes_and_collections/marker_path`
* :doc:`/gallery/lines_bars_and_markers/scatter_star_poly`


.. |m00| image:: /_static/markers/m00.png
Expand Down