Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas plot a repeating dataframe

Tags:

python

pandas

I'm trying to graph a pandas dataframe that contains 2 columns as shown below:

For i in data1:
  for j in data2:
      traces.append(
           go.Scatter(
                 x=df['A'],
                  y=df['B']
               )
           )

plot

tab

Column A has repeating values. When I Plot them it plots the first points correctly (column 'A' 1,2,3 column 'B' 2,5,6) but when it goes to plot the second set of repeating values 'A' 1,2,3 'B' 4,2,3 it draws a line from 'B' point 6 to the next point on 'B' point 2. It doesn't start again as shown below.

from this:

Not

to this:

Yes

like image 734
magicsword Avatar asked Sep 05 '26 13:09

magicsword


1 Answers

Basically, you need to plot each three lines separately:

ax = plt.axes()
df['span'] = df.index // 3 # Assign identical markers to each span
df.groupby('span').apply(lambda x: x.plot(x='A', y='B', legend=False, ax=ax)
plt.show() # If not in ipython
like image 50
DYZ Avatar answered Sep 08 '26 01:09

DYZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!