gnuplot contour plot of data in XYZ array to Matplotlib

Viewed 528

I have data files that have the following x, y, z structure:

   -0.2385905666       -0.0131579757       -0.0000000035
   -0.2385905666       -0.0114839591       -0.0000000096
   -0.2385905666       -0.0098099425       -0.0000000249
   -0.2385905666       -0.0081359259       -0.0000000613
   -0.2385905666       -0.0064619093       -0.0000001440

I currently use gnuplot to plot the data:

splot [0:4] [0:7] "xyzData.dat" using ($1):($2):($3) with lines

The resulting plots look like this example.

I want to use Python 3.7/Matplotlib instead. I have tried various surface and contour plotting methods and keep running into a problem with my Z data. For example, I tried this:

plt.contourf(x, y, z, 100)

I get the error below and don't understand why based on similar posts here at Stackoverflow, although I'm guessing it may have something to do with a grid definition:

Input z must be a 2D array.

At any rate, I am hoping that there is a different plotting method that would be more appropriate. If anyone has a newbie-level suggestion about where to start, I would be grateful.


Update: I came across this post: How to do a contour plot from x,y,z coordinates in matplotlib? (plt.contourf or plt.contour)

It almost works, as shown below. However, I can't figure out how to modify the colors or contour spacing to be more similar to my gnuplot example above. If anyone knows, I would be very grateful for any hints! Example

0 Answers
Related