petermckeeverPerform / themepy

An open source theme selector for matplotlib
MIT License
72 stars 9 forks source link

Add support for SVG dots #5

Open koenvo opened 3 years ago

koenvo commented 3 years ago

Followup on https://twitter.com/unravelsports/status/1340667041448161281

Goal

It would be great to have a way to use SVG instead of regular dots (koen: should use correct name here).

Steps

  1. Make the goal more concrete.
  2. Discuss possibilities from a matplotlib perspective
  3. Discuss possibilities from a themepy perspective
  4. Define implementation
petermckeeverPerform commented 3 years ago

The initial method I am using to include SVGs is to collect them in a font and using matplotlib.font_manager.FontProperties to include them as icons. The downside to this appears to be that the size used for font is not == size used for markers, and svg icons(glyphs??) are not centering correctly and This could be an issue in how svgs are being centered in the font creation tool though...

Being able to import svgs directly would mean we should be able to achieve a few steps, provided the svgs that are importable are created specifically for the purposes of plotting so ids etc.. can be used within a function to then set color, adjust line width etc...

Thoughts on functionality:

create a theme.scatter function that takes similar args, kwargs to pyplot.scatter: x, y, s(size), marker(name of the svg file to import), color(need a way of passing this to the svg element to update color attr), linewidth(need a way of passing to svg element to update stroke-width)

Being able to handle all svgs is probably outside of the scope of this package however. As we will most likely only have a handful of markers (circle, square, triangle, hexagon, x, caret etc..), I wonder if it is better to take the svg files and merge paths in inkscape into one path, then use matplotlib's Path to draw markers. This should allow us to use the size arg of plt.scatter and scale markers correctly with matplotlib's built in markers.

As this is mainly for "hand-drawn" styles, a small collection of similar shapes should be used that can be random.choice'd with a random rotation to give the appearance that they have each been hand-drawn and look different from other similar markers.