0

I am trying to plot on the secondary axis of all subplots of a bar chart, but I was only successful showing the secondary plot on one of the subplots (see image below). I tried:

df[['loan_amnt','int_rate']].plot(kind='bar',subplots=True,layout=(1,2), figsize=(15,5))
df['dti'].plot(secondary_y=True, marker='d', style='g:');

and got see below:

enter image description here What can I add to this code to ensure that the secondary plot is displayed on both subplots.

1
  • I also tried using for loop but it didn't work. Someone please help answer question. Commented Nov 21, 2017 at 16:10

1 Answer 1

1

I was able to solve this using the code below:

fig = plt.figure(figsize=(15,5))

cx0 = fig.add_subplot(121)
cx1 = cx0.twinx()
cx2 = plt.subplot(122)
cx3 = cx2.twinx()

rate_amnt_byGrade['loan_amnt'].plot(kind='bar', ax=cx0)
rate_amnt_byGrade['dti'].plot(ax=cx1, secondary_y=True)
rate_amnt_byGrade['int_rate'].plot(kind='bar', ax=cx2)
rate_amnt_byGrade['dti'].plot(ax=cx3, secondary_y=True)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.