-1

I have a DataFrame, which looks something like this:

    date    organization    percent
85  2018-10-01  org1    0.350875
88  2018-10-02  org1    0.341221
... ... ... ...
3961    2018-10-01 org2 0.292511
3964    2018-10-02 org2 0.418349

I need to plot the time series for each organization in the same plot.

I first tried using a best-fit line for a scatterplot, then sns.lmplot and sns.regplot but I only seem to be able to plot all orgs together. I then found this answer here Pandas: plot multiple time series DataFrame into a single plot but I've been struggling to replicate the formatting. How do I do this? Thanks!

  • 3
    What have you tried? Can you plot the time series for one of the organizations? Where are you stuck? SO isn't a "get people to code for free" service, it's a helping each other community, and you're gonna get downvotes if you don't show some effort. Just a friendly tip... (Maybe you haven't read https://stackoverflow.com/help/how-to-ask) – ShlomiF Dec 03 '18 at 07:03
  • Thanks for the tip, I edited my question. I've been struggling with this for well over an hour. – Yordan Penev Dec 03 '18 at 07:19

1 Answers1

-1

One way is this:

import matplotlib.dates as mdates
grouped_df = df.groupby('organization')
fig, ax = plt.subplots()
for key, item in grouped_df:
    plt.plot_date(item['date'], item['percent'], '-', label=str(key))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%d-%m-%Y'))
ax.xaxis.set_major_locator(mdates.DayLocator(interval=1))
plt.legend()
plt.show()

enter image description here

Joe
  • 12,057
  • 5
  • 39
  • 55
  • @Downvoter, can you please tell me how can i improve the answer and what is wrong in it? – Joe Dec 03 '18 at 10:19