Python Forum

Full Version: Gridding and ploting
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,

I have a txt file with 4 columns. The first two (y,x) are coordinates and the last one (z) is density. Here's my input:

Output:
    y          x     h      z 54.424013 -6.33163 210.9 2347.553 54.429837 -6.330484 198.9 2156.3 54.418983 -6.326504 193.8 2465.166 54.439936 -6.331769 178.6 2406.85 54.431123 -6.327935 175.6 2045.064 54.421964 -6.324441 169.2 2482.016
I'd like to use x,y,z to construct a gridd and plot using plt.contourf(x,y,z). The desired output is a figure that can be used like a map, showing the distribution of the density on the area delimited by the coordinates.

I tried something like that but without success:

#!/usr/bin/env python3

import numpy as np
from scipy.interpolate import griddata
import matplotlib.pyplot as plt

with open("lagan200.txt","r") as fh:
    y,x,h,z=np.loadtxt(fh, delimiter=' ',usecols=[0,1,2,3], unpack=True)
    zz = np.meshgrid(z, indexing='ij')    
    test = plt.contourf(x,y,zz)
Thanks for the help !!
(Jan-18-2017, 12:39 PM)Larz60+ Wrote: [ -> ]Check the following to see if they may be of help (all but the last use matplotlib)
http://matplotlib.org/mpl_toolkits/mplot...orial.html
http://matplotlib.org/examples/pylab_exa..._demo.html
http://matplotlib.org/examples/mplot3d/c...demo3.html

https://plot.ly/python/3d-surface-plots/

Thanks !! I'll try this.