Python Forum
Gridding and ploting - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Gridding and ploting (/thread-1653.html)



Gridding and ploting - Felipe - Jan-18-2017

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 !!


RE: Gridding and ploting - Larz60+ - Jan-18-2017

Check the following to see if they may be of help (all but the last use matplotlib)
http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html
http://matplotlib.org/examples/pylab_examples/contour_demo.html
http://matplotlib.org/examples/mplot3d/contour3d_demo3.html

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


RE: Gridding and ploting - Felipe - Jan-19-2017

(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/mplot3d/tutorial.html
http://matplotlib.org/examples/pylab_examples/contour_demo.html
http://matplotlib.org/examples/mplot3d/contour3d_demo3.html

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

Thanks !! I'll try this.