has2k1 / plotnine

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

Add theme_tufte()? #536

Closed hyiltiz closed 3 years ago

hyiltiz commented 3 years ago

Edward Tufte's The Visual Display of Quantitative Information and Envisioning Information are highly regarded by the scientific community and graphics designers, deemed as the "bible" for graphs designs. With Hadley Whickham's syntax (API) for plots, it is possible to implement some of the design principles of the books into a theme_() function. In fact, R::ggthemes::theme_tufte() is such an implementation. While it is not part of the official R::ggplot package, it is very commonly used, and has a clean style somewhat similar to theme_bw().

Would it be within the scope of this project to include such a function if implemented? Would it be an interest of the project implement it someday?

has2k1 commented 3 years ago

I welcome a theme_tufte if it can be implemented as simply as the current themes. For reference checkout my response to https://github.com/has2k1/plotnine/issues/524 which is about theme_prism.

Either way it is good to implement it to see what hoops you have to jump through to have it done.

hyiltiz commented 3 years ago

Based on how theme_tufte is actually implemented [1], it seems quite straightforward to translate it into Python. I am not sure if R::ggthemes does anything special after the function R::ggthemes::theme_tufte()(in the link below) is evaluated using the R object systems s.t. its output gets decorated or processed somehow. If not, it seems its implementation should be straightforward enough given theme_bw() is already implemented by plotnine and element_blank() are also all provided.

I should be able to come up with a simple pull request for this.

[1] https://github.com/jrnold/ggthemes/blob/main/R/tufte.R

hyiltiz commented 3 years ago

Sent a pull request. It loaded fine and when called like the following:

from plotnine import *
import pandas as pd

data = pd.DataFrame({'x': range(9), 'y': range(9)})
(ggplot(data) + aes(x='x', y='y') + geom_point() + theme_tufte())

the resulting figure plotnine_theme_tufte looks fine as well.

Also including a basic unit test along with the feature in the pull request #541. I hope it is lightweight and simple as you mentioned; it is certainly much lightweight and simpler than plotnine::theme_xkcd(). Looking forward to any feedback.