How do i plot the graph side by side for comparison?

Carlo Silanu

I have made 2 bar graphs that goes like

dirmedtop.plot.barh()

enter image description here

dirmeantop.plot.barh()

enter image description here

now I tried to do

fig, (ax1, ax2) = plt.subplots(1, 2)
fig.suptitle('Horizontally stacked subplots')
ax1 = dirmedtop.plot.barh
ax2 = dirmeantop.plot.barh

but the result shows a typerror 'Axessubplot' not callable and this.

enter image description here

I want the bar graphs to be side by side so that i can compare. Can anyone help me do this?

ultimately i want the graphs to look like this

enter image description here

what i mean by dirmedtop and dirmeantop top is this. dirmedtop is the top 10 directors with highest median gross per director. dirmeantop is the top 10 directors with highest average imdb score.

dirmean= df.loc[df['director_name'].isin(director2.index)].groupby('director_name')['imdb_score'].mean()
dirmean 
dirmeansort= dirmean.sort_values(ascending=False)
dirmeansort
dirmeantop=dirmeansort.head(10)
dirmeantop

director_name
Christopher Nolan    8.425000
Quentin Tarantino    8.200000
Stanley Kubrick      8.000000
James Cameron        7.914286
David Fincher        7.750000
Peter Jackson        7.675000
Martin Scorsese      7.660000
Wes Anderson         7.628571
Paul Greengrass      7.585714
Sam Mendes           7.500000
Name: imdb_score, dtype: float64

dirmed= df.loc[df['director_name'].isin(director2.index)].groupby('director_name')['gross'].median()
dirmed
dirmedsort= dirmed.sort_values(ascending=False)
dirmedsort
dirmedtop= dirmedsort.head(10)
dirmedtop

director_name
Jon Favreau          312057433.0
Peter Jackson        236579815.0
Christopher Nolan    196667606.5
Bryan Singer         156142402.0
James Cameron        146282411.0
Sam Raimi            138480208.0
Michael Bay          138396624.0
Steven Spielberg     132014112.0
Tom Shadyac          128769345.0
Jay Roach            126561111.0
Name: gross, dtype: float64
jezrael

Add parameter ax to Series.plot.barh and also sorting both, for add space between is used subplots_adjust:

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10,5))
plt.subplots_adjust(wspace = 0.7)
fig.suptitle('Top 10 movie directors')
dirmeantop.rename_axis(None).sort_values().plot.barh(ax=ax1, title='By IMDB rank')
dirmedtop.rename_axis(None).sort_values().plot.barh(ax=ax2, title='By Gross')
ax1.set_ylabel('Director')
ax1.set_xlabel('IMDB Score')
ax2.set_xlabel('Gross')

g

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I plot two countplot graphs side by side in seaborn?

How do I plot stacked histograms side by side in matplotlib?

How do I move a Period to the other side of a comparison?

How do I move images side by side?

How do I plot a non-stacked and non-side-by-side horizontal bar chart with matplotlib/pandas?

How do I plot stacked barplots side by side in python? (preferentially seaborn)

How to do a side-by-side bar plot in ggplot2?

How do I make two buttons side by side and responsive?

How do I move objects side to side with lance

How do I make for loops run side by side?

In Javascript, how do I print 2 diagrams side by side?

How can I do "svn diff" side-by-side in emacs

C++, How do i write cout output side by side?

How do I place two or more ASCII images side by side?

How do i place these 2 buttons in different forms, side by side

How do I know if a lib is server side, client side or both?

How do I put two or more images side by side in HTML?

How do I add JPanel/JSplitPane components side by side in a Frame?

How do I put these text and icon side by side?

How do I display a list and a list of lists side by side

How do I center grid elements that are side by side in CSS Grid?

How do I align a checkbox and edittext field side by side in android?

How to plot charts side by side with a forloop

how to plot 2 histograms side by side?

Matplotlib: How do I add a 1 inch gap to the left side of my plot?

How do I change the GPU graph that Windows Task Manager shows on the left side?

How do I transfer the underscore to the left side?

How do I add a button on side of a listview

How to specify each variable position (graph side) in a plot.loglm plot