I have a file "data.dat" following data:
[[0.2 0.3 0.4][0.3 0.2 0.4][0.5 0.3 0.4]]
Now I am reading this data from file as
f=open("data.dat","r")
z=f.read()
f.close()
I have x=[1 2 3]
& y=[1 2 3]
. I made a meshgrid from x
& y
as
X,Y=plt.meshgrid(x,y)
Now I am trying to do contour plot using
plt.contourf(X,Y,Z)
But it is showing error as: ValueError: could not convert string to float: [[0.2 0.3 0.4][0.3 0.2 0.4][0.5 0.3 0.4]]
Any suggestion about how to read Z
array as float from file or to write the "data.dat" file in other way?