has2k1 / plotnine

A Grammar of Graphics for Python
https://plotnine.org
MIT License
3.89k stars 209 forks source link

real fivethirtyeight / "The Economist" style theme #586

Open kraxli opened 2 years ago

kraxli commented 2 years ago

Hi thanks for your great package! Is there a way to easily (e.g. by theme) make real fivethirtyeight / "The Economist" style plots? This would (most importantly) include:

fivethirtyeight

538_title_alignment

the source of the screen shot is How to Generate FiveThirtyEight Graphs in Python where all steps are describe to generate a FiveThirtyEight Graphs (manually) directly by matplotlib.

has2k1 commented 2 years ago

There isn't a way to do it easily. You would even have to drop down into matplotlib to get the exact look! If I remember correctly, 538 used to do their plots in ggplot2, then finish up in inkscape or some other program. With Matplotlib as backend, placing stuff pixel-perfect around the plot can be very finicky, as you can see at the link.

kraxli commented 2 years ago

Many thanks for coming back! A full fledged theme for 538 may be over the top (especially the line labeling) . However, some elements would probably be feasible. I am thinking of:

P.S. interesting that "Fivethirtyeight" uses ggplot2 with inkscape. Would you know what the journal "The Economist" uses?

has2k1 commented 2 years ago
  • proper left alignment of title (to some extend already there)
  • subtitles
  • captions / signature bar (left & right / block alignment); I think this is in the pipeline, right?

Given what matplotlib gives us to work with, automatic precise alignment is hard and that affects the 3 points above. I will be exploring this area soon and maybe we could do better.

kraxli commented 2 years ago

Thanks :-)

has2k1 commented 1 year ago

We now have a layout manager, this feature could not make the upcoming release but will definitely make the one that follows.

jrr96 commented 1 year ago

Thanks a lot for the amazing library!

Not sure if this would be covered by the implementation that you have in mind but I think it might be somewhat related. I would love to see the possibility of the legend alignment to be done relative to axis+panel, not just panel.

For example, in the latest release, if you use legend position bottom, the legend will appear below the chart, its center aligned in the same vertical of the center of the panel. I would love to have the possibility of aligning it to the center of the combined size of axis and panel.

To me, this causes that when I glance over the chart, the legend seems to be not correctly aligned since my eyes cannot ignore the presence of the axis. It is something very minor but, at least in my eyes, it makes quite a difference in the aesthetics of charts.