0

Hey there I'm pretty new to using matplotlib and am trying to plot multiple datasets on the same figure, like so:

graph_df_pivot = df1.pivot_table(index='source_dt', values='num_rws', fill_value=0)
graph_df_pivot2 = df2.pivot_table(index='source_dt', values='num_rws', fill_value=0)
ax = graph_df_pivot.plot(kind='line', figsize=(20, 5), grid=True, title='')  # , use_index=True)
ax.set_xticks(range(0, len(graph_df_pivot.index.tolist())))
ax.set_xticklabels([str(i) for i in graph_df_pivot.index.tolist()], rotation=90)
ax.set_xticks(range(0, len(graph_df_pivot2.index.tolist())))
ax.set_xticklabels([str(i) for i in graph_df_pivot2.index.tolist()], rotation=90)
plt.show()

This is only plotting the data from the first dataset and the second is being overlooked. Any help would be greatly appreciated!

2
  • 1
    I don't see any plot command for the second dataset in your code?! Commented Jun 24, 2020 at 19:14
  • Thanks for the comment! I added a plot command however now I'm getting a second new graph rather than one graph with both data sets. I added code graph_df_pivot2.plot(kind='line', figsize=(20,5), grid=True, title='')#, use_index=True code Commented Jun 25, 2020 at 16:36

1 Answer 1

1

Each plot command by default creates a new Axes unless you pass an existing Axes object to plot on with the ax parameter:

ax = graph_df_pivot.plot(kind='line', figsize=(20, 5), grid=True, title='') 
graph_df_pivot2.plot(kind='line', ax=ax)
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.