0

I have a CSV-File, which contains 3 columns:

temp;val1;val2
350;0.1;1
350.1;0.11;1.1
350.5;0.13;1.23
350.6;0.15;1.36
351.1.1;0.18;1.58
352.2.5;0.22;1.79
...

I would like to create an heat map out of this 3 columns. 'Temp' should be on the x-axis and 'val1' on the y-axis. The value for the color should be 'val2'. But I have troubles creating the correct data format for the third column... Has anyone an idea? Or is there any simplier way to accomplish this? Thanks in advance

train_csv = pandas.read_csv('./training.csv')
train = train_csv.values
x2d, y2d = np.meshgrid(train[:, 0], train[:, 1])
z2d =?
plt.pcolormesh(x2d, y2d, z2d)
plt.show()
schuetzi
  • 35
  • 5
  • What's wrong with `z2d = train[:, 2]` ? – JohanC Apr 02 '20 at 14:21
  • sorry I just created Dummy Data for this post... my original data is of course with decimal. The thing is, that I have no clue how to create the matrix for the third column which I called z2d... – schuetzi Apr 02 '20 at 14:28
  • If I use "z2d= train[:, 2] I get this error message for pcolormesh: "ValueError: not enough values to unpack (expected 2, got 1)" – schuetzi Apr 02 '20 at 14:30
  • OK. `pcolormesh` needs it z-parameter to be a 2D mesh. If everything is already a mesh with M rows and N columns, use `x2d = train[:, 0].reshape(M,N)`, similar for y and z – JohanC Apr 02 '20 at 14:45
  • If the data isn't in a regular mesh, try to use `tricontourf(train[:, 0],train[:, 1],train[:, 2])` – JohanC Apr 02 '20 at 14:47
  • each columns has 300 Values – how should I determine M and N? – schuetzi Apr 02 '20 at 14:48
  • The example data don't look like a mesh. The first temp should be repeated N times each time with different val1, then the second temp repeated N times, again with the same val1 values. So, better first try tricontourf to see how the data look like. – JohanC Apr 02 '20 at 14:53
  • There is already a [post](https://stackoverflow.com/questions/35168638/matplotlib-plot-x-y-z-data-from-csv-as-pcolormesh) about a similar problem and they solved it with reshape, but honestly I do not understand the solution... I tried to execute `tricontourf`, but I received an error instead: "z = np.ma.asarray(args[0]) IndexError: list index out of range" – schuetzi Apr 02 '20 at 15:00
  • It is unclear what `args` is here, nor whether `args[0]` exists. – JohanC Apr 02 '20 at 15:04

0 Answers0