Mitchell Markoff
Mitchell Markoff

Reputation: 41

Matplotlib plotting multiple datasets on same figure using setxticks python

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!

Upvotes: 0

Views: 57

Answers (1)

Stef
Stef

Reputation: 30589

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)

Upvotes: 1

Related Questions