Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gridding and ploting
#1
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 !!
Reply
#2
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/
Reply
#3
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ploting i,j,k,r,g,b data from file p222 0 1,413 Jul-15-2019, 05:31 PM
Last Post: p222

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020