Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try to use the following code. This might help you -- it's the same thing which was in the <a href="http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data" rel="noreferrer">Cookbook</a>:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt from matplotlib.mlab import griddata # with this way you can load your csv-file really easy -- maybe you should change # the last 'dtype' to 'int', because you said you have int for the last column data = np.genfromtxt('output.csv', dtype=[('x',float),('y',float),('z',float)], comments='"', delimiter='|') # just an assigning for better look in the plot routines x = data['x'] y = data['y'] z = data['z'] # just an arbitrary number for grid point ngrid = 500 # create an array with same difference between the entries # you could use x.min()/x.max() for creating xi and y.min()/y.max() for yi xi = np.linspace(-1,1,ngrid) yi = np.linspace(-1,1,ngrid) # create the grid data for the contour plot zi = griddata(x,y,z,xi,yi) # plot the contour and a scatter plot for checking if everything went right plt.contour(xi,yi,zi,20,linewidths=1) plt.scatter(x,y,c=z,s=20) plt.xlim(-1,1) plt.ylim(-1,1) plt.show() </code></pre> <p>I created a sample output file with an Gaussian distribution in 2D. My result with using the code from above:</p> <p><img src="https://i.stack.imgur.com/QhwZw.png" alt="Gaussian distribution in 2D"></p> <p><strong>NOTE:</strong></p> <p>Maybe you noticed that the edges are kind of cropped. This is due to the fact that the <code>griddata</code>-function create masked arrays. I mean the border of the plot is created by the outer points. Everything outside the border is not there. If your points would be on a line then you will not have any contour for plotting. This is kind of logical. I mention it, cause of your four posted data points. It seems likely that you have this case. Maybe you don't have it =)</p> <p><strong>UPDATE</strong></p> <p>I edited the code a bit. Your problem was probably that you didn't resolve the dependencies of your input-file correctly. With the following code the plot should work correctly. </p> <pre><code>import numpy as np import matplotlib.pyplot as plt from matplotlib.mlab import griddata import csv data = np.genfromtxt('example.csv', dtype=[('x',float),('y',float),('z',float)], comments='"', delimiter=',') sample_pts = 500 con_levels = 20 x = data['x'] xmin = x.min() xmax = x.max() y = data['y'] ymin = y.min() ymax = y.max() z = data['z'] xi = np.linspace(xmin,xmax,sample_pts) yi = np.linspace(ymin,ymax,sample_pts) zi = griddata(x,y,z,xi,yi) plt.contour(xi,yi,zi,con_levels,linewidths=1) plt.scatter(x,y,c=z,s=20) plt.xlim(xmin,xmax) plt.ylim(ymin,ymax) plt.show() </code></pre> <p>With this code and your small sample I get the following plot:</p> <p><img src="https://i.stack.imgur.com/52Jeh.png" alt="The sample plot"></p> <p>Try to use my snippet and just change it a bit. For example, I had to change for the given sample csv-file the delimitter from <code>|</code> to <code>,</code>. The code I wrote for you is not really nice, but it's written straight foreword. </p> <p>Sorry for the late response. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload