1

I managed to plot a few charts out with using this for loop:

for i in df.columns[2:7]:
   df.plot.scatter(x='out_date', y=i, figsize = (10,7))
   plt.axvline(x=cutoff_date, color='r')
   plt.xlabel('out date')
   plt.ylabel('sucesses')

I wanted to add titles to the plots using the header of a different dataframe with the following code but the title will only be added to the last plot instead of every plot:

for x in df2.columns[67:72]:
   plt.title(x)

Is there a way to fix this?

1 Answer 1

1

Try to zip your 2 dataframes:

for i, title in zip(df.columns[2:7], df2.columns[67:72]):
   ax = df.plot.scatter(x='out_date', y=i, figsize = (10,7), title=title)
   ax.axvline(x=cutoff_date, color='r')
   ax.set_xlabel('out date')
   ax.set_ylabel('sucesses')

You can also use AxesSubplot instance returned by df.plot methods instead of functions of plt module.

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.