Josh Ortega
Josh Ortega

Reputation: 179

Plot on different axis

I'm trying to plot two series of different scales but I can't seem to figure out the second_y parameter. Code so far:

googletrends_df['Chipotle Mexican Grill: (United States)'].plot(figsize = (15,8), legend = True, second_y = googletrends_df['TOTAL ADSPEND'])
googletrends_df['TOTAL ADSPEND'].plot(legend = True);

But it doesn't seem to be plotting the second axis as seen below:

enter image description here

Upvotes: 0

Views: 51

Answers (1)

Anurag Dabas
Anurag Dabas

Reputation: 24314

import matplotlib.pyplot as plt

Try:

ax=googletrends_df['Chipotle Mexican Grill: (United States)'].plot(legend=True)
googletrends_df['TOTAL ADSPEND'].plot(figsize=(15,8),secondary_y=True,ax=ax,legend=True)
plt.show()

Since you didn't provide your dataframe so I tested this on sample dataframe:

#sample dataframe
googletrends_df=pd.DataFrame(np.random.randn(6,2),columns=['Chipotle Mexican Grill: (United States)','TOTAL ADSPEND'])

Upvotes: 1

Related Questions