1
$\begingroup$

I want to plot multiple plots. The data is stored in a pandas dataframe and each row should be a seperate plot. Each row has an ID (ZRD_ID) which doenst matter and a date (TAG) and 24 values to be plotted.

import pandas as pd
import numpy as np

df = pd.read_csv('./Result_set_edited.csv')
df = df.drop("ZRD_ID", axis=1).drop("TAG", axis=1)

x = df.iloc[[0]]
print(df.head())

returns:

     W01     W02     W03    W04    W05  ...     W20    W21    W22    W23    W24
0  72616  156076  141025  72629  72631  ...       0      0      0      0      0
1  67114  171650  139920  67291  67292  ...  172924  93511  72445  72445  72445
2  66893  161919  134041  66913  66911  ...  166244  86672  67114  67120  67124
3  66603  171297  134227  66615  66631  ...  166078  86622  66871  66877  66879
4  66759  167198  133523  67126  67128  ...  163999  74525  66562  66568  66574

To start easier, since I am really new to this I thought of plotting the first line alone first.

since the columns are named 'W01', 'W02', ... , 'W24' I thought I coould use them as labels for the x-axis. I just didn't find a way to do so, since its the header of the df I guess. So i created a new array and tried to plot it with the first row of my Dataframe:

y = np.arange(0,24,1)
y.reshape(1,24)
print(y)
print(df.iloc[[0]].values)
plt.plot(y, x)
plt.show()

when trying to plot my values I get the following Error:

ValueError: x and y must have same first dimension, but have shapes (24,) and (1, 24)

thanksfor the help on how to fix the Error for plotting the first line.

PS: I would appreciate some hints on how to improve my question, since it is my first one.

Cheers

$\endgroup$

1 Answer 1

0
$\begingroup$

If I correctly got what you meant: you want to plot the first row of all the columns? I guess this could work. x= range(0,24) y = df.iloc[0,:].values xticks = df.columns.tolist() I'm assuming you want a line plot

plt.plot(x,y) plt.xticks(xticks) # to change the x ticks of the graph. plt.show()

The '0' signifies the first row and ':' for all the columns.

$\endgroup$
2
  • 1
    $\begingroup$ Thanks! it worked with a little change: xticks = x (instead of the rercommended xticks = df.columns.tolist()) $\endgroup$
    – CRoNiC
    Commented Sep 11, 2019 at 12:27
  • $\begingroup$ I'm glad it worked. $\endgroup$
    – Gozie
    Commented Sep 11, 2019 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.