To see the xkcd webcomic and to explore further about concepts covered in this lesson, you can check out the following resources:
Visual Style Using Themes
00:00 In this lesson, you’ll learn about how you can use themes to change the look and feel of the plots that you’re creating with plotnine. There’s a couple of themes built-in, and you’re going to see two of them in action right now.
If you head back over to your Jupyter Notebook, you can do these imports. I already wrote them out for you here. It’s going to be the
mpg dataset again, and you’re just using
aes() (aesthetics), and
geom_bar() to create a plot.
00:24 So, you’re doing a bar plot on the class of the cars again. And just to show you, this is how the default theme looks like that plotnine uses. And now you can change these themes by just adding another layer in here.
So, similar to how you added the layers before, you can say
from plotnine import theme_dark, for example. And then you can add the dark theme down here,
theme_dark(), and it’ll change the look of your plot.
There’s a couple of themes that are available like this. You can choose the ones that fit for what you want to display. A fun one I wanted to show you here is
theme_xkcd. If you know, xkcd is writing web comics and has a specific style of drawing graphs, and you can simulate that in here as well.
01:14 So if you apply the xkcd theme, then you get a plot that looks like this, which, if you compare it to some of the web comics, this is kind of like the style that this person uses to create graphs.
01:33 And this is how you can use themes to change the look and feel of your plots. In the next lesson, you’re going to learn how you can export some of these plots that you generated and save them as files.
Become a Member to join the conversation.