1

I am new to Python , and I know is somehow a basic question but has taken my time for a while.

I have table with four columns as date, time, flow, dayType which show how many cars pass some area in specific times in two days(2018-10-05 ,2018-10-12) .

Now I want to plot the corresponding flow of each day base on the time on same plot(axes) to compare these days , but the only things I get is an empty plot without showing any diagram!

import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from numpy import split
%matplotlib inline
sns.set()
data = pd.read_excel('friday_frame.xlsx', names=['date', 'time', 'flow', 'dayType'])
fig, ax = plt.subplots(figsize=(12, 4))
dataPivot = pd.pivot_table(data, values='flow', index='time', columns='date').plot()
plt.ylabel('flows');
Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
mahsa
  • 58
  • 1
  • 7

1 Answers1

0

I used this code to make a dummy-DataFrame, similar to what you're doing:

data = pd.DataFrame(data={"date": ["01/01/2019", "01/01/2019", "01/02/2019", "01/02/2019"],
                          "time": [pd.Timestamp(year=2019, month=1, day=1, hour=9),
                                  pd.Timestamp(year=2019, month=1, day=1, hour=13),
                                  pd.Timestamp(year=2019, month=1, day=2, hour=9),
                                  pd.Timestamp(year=2019, month=1, day=2, hour=13)],
                          "flow": [1,2,3,4], "dayType": ["morning", "morning", "afternoon", "afternoon"]})
dataPivot = pd.pivot_table(data, values='flow', index='time', columns='date'); display(dataPivot) #Pivot Table Values
dataPivot.plot(kind="bar") #The Graph

It outputs this:

Output of above code

What is different here than what you are doing?

A couple of things, but nothing major.

First, plot() needs some kind of graph to plot, in this case I chose bar (kind="bar"). Of course, you can choose whatever works for you.

Second, I chose to not chain arguments together so I could see my table and my plot. Since I ran this in Jupyter, I needed to use display to show more than one thing in a cell.

Hope this helps!

zerecees
  • 697
  • 4
  • 13
  • Thanks so much for your attention , but I still have some problem , now I think it because the flow for some times is missing , I mean e.g I have flow for 2019-05-01 like 4340 but this time for 2019-12-01 I have nothing – mahsa Jun 15 '19 at 11:24