Skip to content

Doc markersupdate #11437

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 2 commits into from
Jun 15, 2018
Merged

Conversation

ImportanceOfBeingErnest
Copy link
Member

@ImportanceOfBeingErnest ImportanceOfBeingErnest commented Jun 14, 2018

PR Summary

Closes #7342 and closes #8556.

#7342 lists a few things to improve about the matplotlib.markers documenation.

This PR fixes those. In particular it

  • adds images of the markerstyles to the table
  • specifies how to use TICKLEFT, CARETLEFT and friends
  • explains what "the size is normalized" means.
  • modifies and improves the marker_reference example

The marker table will look like

image

For completeness/reproducibility, here is the code to produce the images:
# adapted from my Stackoverflow answer
# https://stackoverflow.com/questions/43021593/how-can-i-export-legend-markers-from-matplotlib-one-at-a-time/43028174#43028174
import matplotlib.pyplot as plt
import numpy as np; np.random.seed(422)
plt.rcParams["legend.labelspacing"] = .7


markers= dict((k,v) for k,v in plt.Line2D.markers.items())
markers.update({"$f$" : "mathtext"})


fig, ax = plt.subplots(dpi=100)
for i, (k,v) in enumerate(markers.items()):
    if v=="nothing": continue
    print("{:02d}".format(i), k,v)
    ax.plot([0,1], [i,i], linestyle="", marker=k, ms=8, label=v, color="C0")

leg = ax.legend(framealpha=1, ncol=3)

def export_legend_handles(fig, leg, filename=None, ext=[".pdf", ".png"], d = [0,0,0,3]):
    """ d = [left, bottom, right, top] pixel to add in the respective dimension """
    import matplotlib.transforms as mtransforms
    boxes = []
    fig.canvas.draw()
    trans = fig.dpi_scale_trans.inverted()
    for vpack in leg._legend_handle_box.get_children():
        for hpack in vpack.get_children():
            drawbox = hpack.get_children()[0]
            w, h, xd, yd = drawbox.get_extent(fig.canvas.get_renderer())
            ox, oy = drawbox.get_offset()  
            pixbox = mtransforms.Bbox.from_bounds(ox-d[0],oy-d[1],w+d[0]+d[2],h+d[1]+d[3])
            inchbox = pixbox.transformed(trans) 
            boxes.append(inchbox)

    filename = filename if filename else __file__[:-3]
    for i, box in enumerate(boxes):
        for ex in ext:
            plt.savefig("{}{:02d}{}".format(filename,i,ex), dpi="figure", bbox_inches=box)

export_legend_handles(fig, leg, filename="m", ext = [".png"], d = [-2,5,-2,5])


def print_mix():
    s = ".. |m{:02d}| image:: /_static/markers/m{:02d}.png"
    for i  in range(42):
        print(s.format(i,i))
print_mix()
plt.show()

PR Checklist

  • Code is PEP 8 compliant
  • Documentation is sphinx and numpydoc compliant

Also see the :doc:`/gallery/text_labels_and_annotations/stix_fonts_demo`.

Integer numbers from ``0`` to ``11`` create lines and triangles. Those are
equally accessible via capitalied variables, like ``CARETDOWNBASE``.
Copy link
Contributor

Choose a reason for hiding this comment

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

capitalized?

Copy link
Contributor

@choldgraf choldgraf left a comment

Choose a reason for hiding this comment

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

This is really nice - I love the viz of each marker in the docs and the wording is definitely improved. I'm +1 on merge once travis is happy unless other folks find anything obviously wrong

@ImportanceOfBeingErnest
Copy link
Member Author

Not sure what the problem of travis-ci is; it looks like it doesn't like itself rather than not liking this PR.

@choldgraf
Copy link
Contributor

I gave it a restart to see if that fixes things

@ImportanceOfBeingErnest
Copy link
Member Author

It didn't. Something is generally going wrong with the ci tests currently, other PRs are affected by the same issue.

@jklymak jklymak merged commit bfa8d61 into matplotlib:master Jun 15, 2018
@jklymak
Copy link
Member

jklymak commented Jun 15, 2018

Merged; I don't think the CI problems are here...

@QuLogic QuLogic added this to the v3.0 milestone Jun 15, 2018
@choldgraf
Copy link
Contributor

🎉

``"H"`` |m16| hexagon2
``"+"`` |m17| plus
``"x"`` |m18| x
``"X"`` |m21| x (filled)
Copy link
Contributor

Choose a reason for hiding this comment

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

@ImportanceOfBeingErnest
This should have been |m24| rather than |m21|, right?

Look for example for "x_filled" in the output of the following script, adapted from yours:

from matplotlib.lines import Line2D

markers= dict((k,v) for k,v in Line2D.markers.items())
markers.update({"$f$" : "mathtext"})

for i, (k, v) in enumerate(markers.items()):
    if v=="nothing":
        continue
    print("{:02d}".format(i), k, v)

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely. Thanks for spotting this. It should be fixed by #11545.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add images of markers to the list of markers list of markers in documentation could be improved
5 participants