2

I have a .txt file with values

x1 y1 z1

x2 y2 z2

etc.

With my previous little experience I was trying to draw a contourf, with this code

import numpy as np import matplotlib from matplotlib import rc import matplotlib.mlab as ml from pylab import * rc('font', family='serif') rc('font', serif='Times New Roman') rc('font', size='9') rc('text', usetex=True) from matplotlib.mlab import griddata import matplotlib.pyplot as plt import numpy.ma as ma from numpy.random import uniform from matplotlib.colors import LogNorm matplotlib.use('pgf') fig = plt.figure() data = np.genfromtxt('Velocidad.txt') matplotlib.rcParams['xtick.direction'] = 'out' matplotlib.rcParams['ytick.direction'] = 'out' rc('text', usetex=True) rc('font', family='serif') x = data[:,0] y = data[:,1] z = data[:,2] xi = np.linspace(0,3000.0, 400) yi = np.linspace(0,4.0, 200) zi = griddata(x,y,z,xi,yi,interp='nn') CS = plt.contourf(xi,yi,zi,200,cmap=plt.cm.jet,rasterized=True) plt.colorbar() plt.xlim(0,3000) plt.ylim(0,4.0) plt.ylabel(r'$t$') plt.xlabel(r'$x$') plt.title(r' Contour de $v(x,t)$') plt.savefig("CampoVel.png", dpi=100) plt.show() 

the problem is the output:

enter image description here

When I see this picture and I look at the data (which is here, in this link) and I don't understand those discontinuities in x=750 and x=1875. And those strange vertical lines all over the plot. Looking at the data I would expect something smooth, at least in those positions, but the output obviously isn't. Is this a problem of griddata()? How can I solve it?

I have been told that as my data is regularly spaced on X and Y, I shouldn't use griddata(), but I have looked examples and I can't get the code to work.

1
  • Can you post an example of your input file (or a subset of it) to make your problem reproducible? Commented May 7, 2013 at 0:07

1 Answer 1

2

If you simply reshape your data after loading it and skip the griddata thing, doing this:

data = data.reshape(81, 201, 3) x = data[...,0] y = data[...,1] z = data[...,2] CS = plt.contourf(x,y,z,200,cmap=plt.cm.jet,rasterized=True) plt.colorbar() plt.show() 

You get this: enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.