0

I am perplexed as to why I can't use scatter with my matplotlib dataframe. I am trying to plot elapsed time as a function of voltage. Whenever I try with plt.plot it works, but I need it as a scatter plot. My data looks like this

filtered_data['Elapsed Time']

5     0 days 00:00:00.002000
6     0 days 00:00:00.003000
7     0 days 00:00:00.003000
10    0 days 00:00:00.005000
11    0 days 00:00:00.005000
15    0 days 00:00:00.007000
17    0 days 00:00:00.008000
20    0 days 00:00:00.010000
21    0 days 00:00:00.010000
24    0 days 00:00:00.011000
27    0 days 00:00:00.013000
31    0 days 00:00:00.015000
35    0 days 00:00:00.017000
36    0 days 00:00:00.018000
37    0 days 00:00:00.018000
38    0 days 00:00:00.019000
40    0 days 00:00:00.020000
41    0 days 00:00:00.020000
42    0 days 00:00:00.021000
43    0 days 00:00:00.021000
47    0 days 00:00:00.023000
49    0 days 00:00:00.024000
50    0 days 00:00:00.025000
54    0 days 00:00:00.026000
55    0 days 00:00:00.027000
...
115   0 days 00:00:00.057000
116   0 days 00:00:00.058000
117   0 days 00:00:00.058000
118   0 days 00:00:00.059000
Name: Elapsed Time, dtype: timedelta64[ms]

similarly my voltage data filtered_data['Voltage']:
5      11.4143
6      11.4039
7      11.3956
10     11.4122
11     11.4060
15     11.4122
17     11.4060
20     11.4184
21     11.4143
24     11.4039
27     11.4060
31     11.3936
35     11.4143
36     11.3894
37     11.4184
38     11.4019
40     11.3936
41     11.4102
42     11.4164
43     11.4081
47     11.3977
49     11.4122
50     11.4164
54     11.4122
55     11.4081
...
115    11.4164
116    11.3936
117    11.4495
118    11.4143
Name: Voltage , dtype: float64

However, when I try to plot it either using:

plt.scatter(filtered_data['Elapsed Time'], filtered_data['Voltage'])

or filtered_data.plot(kind='scatter',x='Elapsed Time'',y='Voltage') (in this case the Elapsed Time and Voltage doesn't even fill in)

or using

filtered_data.plot.scatter(x='Elapsed Time'',y='Voltage')

Either way I try it I always get this error: TypeError: The DType could not be promoted by . This means that no common DType exists for the given inputs. For example they cannot be stored in a single array unless the dtype is object. The full list of DTypes is: (, )

I listed what I tried above, I was expecting a scatter plot of elapsed time versus voltage

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • Welcome to Stack Overflow! Please provide a [mre] that includes your code, relevant data, and desired output. As it is, this question is missing important details and will likely be closed. – h0r53 Jun 05 '23 at 18:42
  • `filtered_data['Elapsed Time'] = filtered_data['Elapsed Time'].dt.total_seconds()` and then plot. You can't plot against a timedelta. – Trenton McKinney Jun 05 '23 at 18:47
  • Check [this answer](https://stackoverflow.com/a/49849072/6368579). They convert the time delta to date time, and then format the result to not display the year, month and day the conversion adds – DSantiagoBC Jun 05 '23 at 18:55
  • @DSantiagoBC that's not a good option for voltage against millisecond time. – Trenton McKinney Jun 05 '23 at 18:59

0 Answers0