Runner Bean
Runner Bean

Reputation: 5155

stop connecting points in pandas time series plot

I have some data in a pandas series and when I type

 mydata.head()

I get:

                       BPM
timestamp   
2015-04-07 02:24:00    96.0
2015-04-07 02:24:00    96.0
2015-04-07 02:24:00    95.0
2015-04-07 02:24:00    95.0
2015-04-07 02:24:00    95.0

Also, when using

 mydata.info() 

I get:

 <class 'pandas.core.frame.DataFrame'>
 DatetimeIndex: 33596 entries, 2015-04-07 02:24:00 to 2015-07-15 14:23:50
 Data columns (total 1 columns):
 BPM    33596 non-null float64
 dtypes: float64(1)
 memory usage: 524.9 KB

When I go to plot using

 import matplotlib.pyplot as pyplot

 fig, ax = pyplot.subplots()
 ax.plot(mydata)

time series plot with points connected

I just get a complete mess, it's like it's joining lots of points together that should not be joined together.

How can I sort this out to display as a proper time series plot?

Upvotes: 2

Views: 2888

Answers (2)

Rodrigo
Rodrigo

Reputation: 580

Just use

mydata.plot(style="o")

and you should get a Pandas plot without lines connecting the points.

Upvotes: 3

Julien Spronck
Julien Spronck

Reputation: 15423

Just tell matplotlib to plot markers instead of lines. For example,

import matplotlib.pyplot as pyplot

fig, ax = pyplot.subplots()
ax.plot(my data, '+')

If you prefer another marker, you can change it (see this link).

You can also plot directly from pandas:

mydata.plot('+')

If you really want the lines, you need to sort your data before plotting it.

Upvotes: 0

Related Questions