简体   繁体   中英

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!

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM