Create a draw_box_plot function that uses Seaborn to draw two adjacent box plots similar to “examples/Figure_3.png”
I am able to create individual box plots
have tried multiple ways to create 2 adjacent box plots but they always end up over lapping in the last column and row i.e. [1st row][2nd column] .
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36
While it would be nice if you told us what exactly you tried so far - what you are looking for is the matplotlib.pyplot.subplots(), where you just define a grid of plots and then just have to properly fill them in.
Yeah the problem if you have multiple plots or “axes-objects” created you have to tell Seaborn which to use with the ax-attribute.
If you don’t, it will add the plot to the whatever the current axes is, which by default is the last one created → hence both times the plot is in the second grid.
Thank you.
I did try ax attribute and indeed were able to get the desired result.
As I am new I don’t now how valid this question would be, but what I was unable to understand with the use of ax attribute is:
while using ax the way i referenced X and Y values in the function had to be changed from
this :
sns.boxplot(x=“month”, y = “Page Views”, data = df_box)
to this :
sns.boxplot(x=df_box[“month”], y = df_box[‘Page Views’], data = df_box, ax = f2)
Must be some error which stems from another source. In my solution I used X and Y like you did in the first version while also using the ax-attribute. So this is entirely possible and I cannot say why this didn’t work for you, but my guess is, you might have missed a comma or so ^^°