msvalkon
msvalkon

Reputation: 12077

How do I plot this DataFrame?

I've got a pandas.DataFrame that looks like this:

>>> print df

      0     1     2     3     4     5     6     7     8     9     10    11  \
0  0.198 0.198 0.266 0.198 0.236 0.199 0.198 0.198 0.199 0.199 0.199 0.198   
1  0.032 0.034 0.039 0.405 0.442 0.382 0.343 0.311 0.282 0.255 0.232 0.210   
2  0.702 0.702 0.742 0.709 0.755 0.708 0.708 0.712 0.707 0.706 0.706 0.706   
3  0.109 0.112 0.114 0.114 0.128 0.532 0.149 0.118 0.115 0.114 0.114 0.112   
4  0.309 0.306 0.311 0.311 0.316 0.513 1.977 0.313 0.311 0.310 0.311 0.309   
5  0.280 0.277 0.282 0.278 0.282 0.383 1.122 1.685 0.280 0.280 0.282 0.280   
6  0.466 0.460 0.465 0.465 0.468 0.508 0.829 1.100 1.987 0.465 0.465 0.463   
7  0.469 0.464 0.469 0.470 0.469 0.490 0.648 0.783 1.095 2.002 0.469 0.466   
8  0.137 0.120 0.137 0.138 0.137 0.136 0.144 0.149 0.166 0.209 0.137 0.136   
9  0.125 0.107 0.125 0.126 0.125 0.122 0.126 0.128 0.132 0.144 0.125 0.123   
10 0.125 0.106 0.125 0.123 0.123 0.122 0.125 0.128 0.132 0.142 0.125 0.123   
11 0.127 0.107 0.125 0.125 0.125 0.122 0.126 0.127 0.132 0.142 0.125 0.123   
12 0.125 0.107 0.125 0.128 0.125 0.123 0.126 0.127 0.132 0.142 0.125 0.122   
13 0.871 0.862 0.871 0.872 0.872 0.872 0.873 0.872 0.875 0.880 0.873 0.872   
14 0.114 0.115 0.116 0.117 0.131 0.536 0.153 0.123 0.118 0.117 0.117 0.116   
15 0.033 0.032 0.031 0.032 0.032 0.040 0.033 0.033 0.032 0.032 0.032 0.032  
      12    13  
0  0.198 0.198  
1  0.190 0.172  
2  0.705 0.705  
3  0.112 0.115  
4  0.308 0.310  
5  0.275 0.278  
6  0.462 0.463  
7  0.466 0.466  
8  0.134 1.678  
9  0.122 1.692  
10 0.122 1.694  
11 0.122 1.695  
12 0.122 1.684  
13 0.872 1.255  
14 0.116 0.127  
15 0.031 0.032  

[16 rows x 14 columns]

Each row represents a measurement value for an analog port. Each column is a test case. Thus there's one measurement for each of the analog ports, in each column.

When I plot this with DataFrame.plot() I end up with the following plot:

incorrect plot

But this presents my rows, the 16 analog ports on the x-axis. I would like to have the column numbers on the x-axis. I've tried to define the x-axis in plot() as below:

>>> df.plot(x=df.columns)

Which results in a

ValueError: Length mismatch: Expected axis has 16 elements, new values have 14 elements

How should I approach this? Below is an example image which shows the correct x-axis values.

right

Upvotes: 0

Views: 334

Answers (1)

TomAugspurger
TomAugspurger

Reputation: 28936

You want something like

df.T.plot()

Plus some other formatting. But that will get you started.

the .T method transposes the DataFrame.

Upvotes: 2

Related Questions