Help combining these two visualizations

Screen Link:

My Code:

#plot details
N = len(quarterly["Quarter"]) #how many bars to show
ind = np.arange(N) #spacing between bars

#bar plots
p1 =, quarterly["Total_Questions"])
p2 =, quarterly["DeepLearning_Questions"])
p3 = quarterly.plot(x="Quarter",

#labels and legend
plt.title('Deep Learning vs. Other Data Science \n Questions by Quarter', fontsize = 25)
plt.ylabel('Number of Questions', fontsize=20)
plt.xlabel('Quarters', fontsize=20)
plt.xticks(ind, quarterly["Quarter"], rotation=90)

plt.legend((p1[0], p2[0], p3[0]),
           ("TotalQuestions", "DeepLearningQuestions", "DeepLearningRate"),
           loc = "best")

What I expected to happen:
I would get a bar chart with stacked bars, showing the total_question and deeplearning_question counts per quarter.

What actually happened:

TypeError                                 Traceback (most recent call last)
<ipython-input-108-7473fb02e62a> in <module>
     16 plt.xticks(ind, quarterly["Quarter"], rotation=90)
---> 18 plt.legend((p1[0], p2[0], p3[0]),
     19            ("TotalQuestions", "DeepLearningQuestions", "DeepLearningRate"),
     20            loc = "best")

TypeError: 'AxesSubplot' object is not subscriptable

I always get super confused with the visualization parts of projects. I have all the data and numbers and what not, but making it into a graph is difficult for me. It seems like there’s a million ways to graph things. I’m basically trying to copy the graph that is in the solution notebook, but I’m trying to do it on my own. I have attached my notebook file just in case.

PopularDataScienceQuestions.ipynb (541.1 KB)

I want these two graphs to be combined:


What I’m trying to recreate:

Click here to view the jupyter notebook file in a new tab

both of these plots are on different scales, so in the picture that you’re trying to create, first bar has a y value of 157 , whereas if you look at yaxis it’s not even close:(it’s below 0.10) so you need to start considering how to fit 2 different plots with different scales in 1 axis, fortunately there’s documentation for that:

btw , you;re getting the error because of legend - just use label=‘something’ in each plot and plt.legend()

1 Like

Thanks for the reply. I ended up going down a deep rabbit-hole of reading all about graphs, axes, labels, and modification and all that jazz. It makes a lot more sense to me now. In the end I was able to get it to work, after lots and lots of reading and testing. Thanks!

1 Like