Is there an equivalent to %+% for plotnine?

Question:

In R’s ggplot2, you can modify the dataset for a saved plot with %+%. Is there an equivalent in Python’s plotnine?

As an example, here is what this looks like in R:

library(ggplot2)

df1 <- data.frame(x = 1:10, y = 1:10 * 2)
p1 <- ggplot(data = df1, aes(x = x, y = y)) + geom_line()

df2 <- data.frame(x = 1:10, y = 1:10 * 3)
p1 %+% df2  # produces the same plot using the df2 data.frame
Asked By: Jake Fisher

||

Answers:

I am not aware about the ggplot function of R, but according to your comments, I think creating a custom function to plot a graph from a df will work.

def create_plots(df):
    #code to create the ggplot

This way you can easily change out the dataframe. I looked at plotnine’s API reference, and there doesn’t seem to be a way to do that.

Answered By: Aditya Gupta
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.