Skip to content

Equal area markers #16891

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
14 changes: 7 additions & 7 deletions doc/api/next_api_changes/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,13 @@ also be accessible as ``toolbar.parent()``.

Path helpers in :mod:`.bezier`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``bezier.make_path_regular`` is deprecated. Use ``Path.cleaned()`` (or
``Path.cleaned(curves=True)``, etc.) instead (but note that these methods add a
``STOP`` code at the end of the path).

``bezier.concatenate_paths`` is deprecated. Use ``Path.make_compound_path()``
instead.
- ``bezier.make_path_regular`` is deprecated. Use ``Path.cleaned()`` (or
``Path.cleaned(curves=True)``, etc.) instead (but note that these methods add
a ``STOP`` code at the end of the path).
- ``bezier.concatenate_paths`` is deprecated. Use ``Path.make_compound_path()``
instead.
- ``bezier.split_path_inout`` (use ``Path.split_path_inout`` instead)
- ``bezier.inside_circle()`` (no replacement)

``animation.html_args`` rcParam
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion doc/api/next_api_changes/removals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Classes, methods and attributes

- ``image.BboxImage.interp_at_native`` property (no replacement)
- ``lines.Line2D.verticalOffset`` property (no replacement)
- ``bezier.find_r_to_boundary_of_closedpath()`` (no relacement)
- ``bezier.find_r_to_boundary_of_closedpath()`` (no replacement)

- ``quiver.Quiver.color()`` (use ``Quiver.get_facecolor()`` instead)
- ``quiver.Quiver.keyvec`` property (no replacement)
Expand Down
12 changes: 12 additions & 0 deletions doc/users/next_whats_new/2020-03-16_markerstyle_normalization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Allow for custom marker scaling
-------------------------------
`~.markers.MarkerStyle` gained a keyword argument *normalization*, which may be
set to *"none"* to allow for custom paths to not be scaled.::

MarkerStyle(Path(...), normalization="none")

`~.markers.MarkerStyle` also gained a `~.markers.MarkerStyle.set_transform`
method to set affine transformations to existing markers.::

m = MarkerStyle("d")
m.set_transform(m.get_transform() + Affine2D().rotate_deg(30))
65 changes: 58 additions & 7 deletions examples/lines_bars_and_markers/scatter_piecharts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
Scatter plot with pie chart markers
===================================

This example makes custom 'pie charts' as the markers for a scatter plot.

Thanks to Manuel Metz for the example.
This example shows two methods to make custom 'pie charts' as the markers
for a scatter plot.
"""

##########################################################################
# Manually creating marker vertices
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

import numpy as np
import matplotlib.pyplot as plt

# first define the ratios
# first define the cumulative ratios
r1 = 0.2 # 20%
r2 = r1 + 0.4 # 40%

Expand All @@ -36,10 +40,55 @@
s3 = np.abs(xy3).max()

fig, ax = plt.subplots()
ax.scatter(range(3), range(3), marker=xy1, s=s1**2 * sizes, facecolor='blue')
ax.scatter(range(3), range(3), marker=xy2, s=s2**2 * sizes, facecolor='green')
ax.scatter(range(3), range(3), marker=xy3, s=s3**2 * sizes, facecolor='red')
ax.scatter(range(3), range(3), marker=xy1, s=s1**2 * sizes, facecolor='C0')
ax.scatter(range(3), range(3), marker=xy2, s=s2**2 * sizes, facecolor='C1')
ax.scatter(range(3), range(3), marker=xy3, s=s3**2 * sizes, facecolor='C2')

plt.show()


##########################################################################
# Using wedges as markers
# ~~~~~~~~~~~~~~~~~~~~~~~
#
# An alternative is to create custom markers from the `~.path.Path` of a
# `~.patches.Wedge`, which might be more versatile.
#

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Wedge
from matplotlib.markers import MarkerStyle

# first define the ratios
r1 = 0.2 # 20%
r2 = r1 + 0.3 # 50%
r3 = 1 - r1 - r2 # 30%


def markers_from_ratios(ratios, width=1):
markers = []
angles = 360*np.concatenate(([0], np.cumsum(ratios)))
for i in range(len(angles)-1):
# create a Wedge within the unit square in between the given angles...
w = Wedge((0, 0), 0.5, angles[i], angles[i+1], width=width/2)
# ... and create a custom Marker from its path.
markers.append(MarkerStyle(w.get_path(), normalization="none"))
return markers

# define some sizes of the scatter marker
sizes = np.array([100, 200, 400, 800])
# collect the markers and some colors
markers = markers_from_ratios([r1, r2, r3], width=0.6)
colors = plt.cm.tab10.colors[:len(markers)]

fig, ax = plt.subplots()

for marker, color in zip(markers, colors):
ax.scatter(range(len(sizes)), range(len(sizes)), marker=marker, s=sizes,
edgecolor="none", facecolor=color)

ax.margins(0.1)
plt.show()

#############################################################################
Expand All @@ -55,3 +104,5 @@
import matplotlib
matplotlib.axes.Axes.scatter
matplotlib.pyplot.scatter
matplotlib.patches.Wedge
matplotlib.markers.MarkerStyle
Loading