Search code examples
pythonggplot2python-ggplot

Where does python ggplot take its default values from


Where does python ggplot take its default values from and how can one change them so that there is no need to use + theme_whatever() every time a plot is created?


Solution

  • I assume you are referring to the ggplot package from http://ggplot.yhathq.com/? There does not seem to be any equivalent to the theme_set function of the ggplot2 R package, the default theme is currently hardcoded to be theme_grey(). I think the best you can do is to define your theme in one place and use it in all plots:

    from ggplot import *
    my_theme = theme_seaborn()
    p = ggplot(aes(x='wt', y='mpg'), data=mtcars) + geom_point()
    print(p + my_theme)
    p2 = ggplot(aes(x='date', ymin='beef - 1000',
                ymax='beef + 1000'), data=meat) + geom_area()
    print(p2 + my_theme)
    

    Alternatively, you can define yourself a small wrapper function that you call instead of the print(... + my_theme) call.