Skip to content

19195 rotated markers#20914

Merged
dstansby merged 22 commits into
matplotlib:masterfrom
deep-jkl:19195-rotated-markers
Oct 5, 2021
Merged

19195 rotated markers#20914
dstansby merged 22 commits into
matplotlib:masterfrom
deep-jkl:19195-rotated-markers

Conversation

@deep-jkl

@deep-jkl deep-jkl commented Aug 26, 2021

Copy link
Copy Markdown
Contributor

PR Summary

Add user supplied transforms and join/cap styles …

Improvement was done in instantiating new instance utilizing deep copy should preserve immutability of MarkerStyle members (e.g. Path, or Transform). However deepcopy of MarkerStyle(r"$|||$") fails. Originally it was needed in lines.py, but I think it can be optimized out to avoid multiple re-instantiation of MarkerStyle.

I followed the discussion for issue #19195 and tried several cases:

from matplotlib import transforms
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
from matplotlib.transforms import Affine2D
from matplotlib.markers import MarkerStyle, JoinStyle, CapStyle

text_style = dict(horizontalalignment='right', verticalalignment='center',
                  fontsize=12, fontfamily='monospace')
marker_style = dict(linestyle=':', color='0.8', markersize=10,
                    markerfacecolor="tab:blue", markeredgecolor="tab:blue")

def format_axes(ax):
    ax.margins(0.2)
    ax.set_axis_off()
    ax.invert_yaxis()

fig, ax = plt.subplots()
fig.suptitle('Marker fillstyle', fontsize=14)
fig.subplots_adjust(left=0.4)

marker_colors = dict(markersize=15,
                    markerfacecolor='tab:blue',
                    markerfacecoloralt='lightsteelblue',
                    markeredgecolor='brown')

for y, fill_style in enumerate(Line2D.fillStyles[1:-1]):
    ax.text(-0.5, y, repr(fill_style), **text_style)
    ax.plot([0,5],[y]*2, linestyle=":", color='darkgrey')
    for x, theta in enumerate([0, 10, 15, 20, 30, 45]):
        ax.plot(x, y, marker=MarkerStyle("o", fill_style, transform=Affine2D().rotate_deg(theta)), **marker_colors)
        ax.text(x, 4, f"{theta}°", **text_style)
format_axes(ax)

plt.show()

fillstyle

fig, ax = plt.subplots()
fig.suptitle('Marker CapStyle', fontsize=14)
fig.subplots_adjust(left=0.1)

marker_inner = dict(markersize=35,
                    markerfacecolor='tab:blue',
                    markerfacecoloralt='lightsteelblue',
                    markeredgecolor='brown',
                    markeredgewidth=8,
                    )

marker_outer = dict(markersize=35,
                    markerfacecolor='tab:blue',
                    markerfacecoloralt='lightsteelblue',
                    markeredgecolor='white',
                    markeredgewidth=1,
                    )

for y, cap_style in enumerate(CapStyle):
    ax.text(-0.5, y, cap_style.name, **text_style)
    ax.plot([0,5],[y]*2, linestyle=":", color='darkgrey')
    for x, theta in enumerate([0, 10, 15, 20, 30, 45]):
        ax.plot(x, y, marker=MarkerStyle("1", transform=Affine2D().rotate_deg(theta), capstyle=cap_style), **marker_inner)
        ax.plot(x, y, marker=MarkerStyle("1", transform=Affine2D().rotate_deg(theta), capstyle=cap_style), **marker_outer)
        ax.text(x, 3, f"{theta}°", **text_style)
format_axes(ax)

plt.show()

capstyle

fig, ax = plt.subplots()
fig.suptitle('Marker JoinStyle', fontsize=14)
fig.subplots_adjust(left=0.1)

marker_colors = dict(markersize=35,
                    markerfacecolor='tab:blue',
                    markerfacecoloralt='lightsteelblue',
                    markeredgecolor='brown',
                    markeredgewidth=8)

for y, join_style in enumerate(JoinStyle):
    ax.text(-0.5, y, join_style.name, **text_style)
    ax.plot([0,5],[y]*2, linestyle=":", color='darkgrey')
    for x, theta in enumerate([0, 10, 15, 20, 30, 45]):
        ax.plot(x, y, marker=MarkerStyle("*", transform=Affine2D().rotate_deg(theta), joinstyle=join_style), **marker_colors)
        ax.text(x, 3, f"{theta}°", **text_style)
format_axes(ax)

plt.show()

joinstyle

list1 = [0, 1] #| x coordinates
list2 = [0, 0] #| y coordinates

p1 = [.5, 0] #| p1 stands for point1, the marker will be placed in this point
marker1 = MarkerStyle(r'$|||$', transform=Affine2D().rotate_deg(45))

plt.plot(list1, list2, 'o-k', linewidth = 1)
plt.plot(p1[0], p1[1], 'k', marker = marker1)

#T# show the results
plt.show()

reproductor

Things that needs to be done:

  • Add modifiers such as (rotated -> returns new rotated instance, and other primitive transformations)
  • Add tests
  • Improve documentation

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [ N/A ] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants