简体   繁体   中英

Given a dataset with X, Y, Z coordinates in Python, how to generate a contour in NumPy?

I have a dataset consisting of something like this:

10 10 4.49872823
10 20 4.48713242
20 10 8.34512345
...
1000 1000 1.91882984

I can load this fine, and I have a means of transforming it into any array that I like.

The problem is that I'm trying to graph it using NumPy in a contour map.

import numpy as np
np.contour(X,Y,Z)

Which only accepts data on a grid using numpy.meshgrid .

Getting the X and Y dataset is no problem, but I can't seem to figure out what format numpy.contour wants the Z value to be in as the documentation is limited. Examples shown show a 3 by X scale array like so

array([2.34556123 4. 4.55345318]
      [4.23245217 5. 2.25376211]
      ...
      [9.14245561 6. 8.24562431])

Which is beyond the scope of the simple coordinate plot that I'm attempting to do.

Do you mean the matplotlib.pyplot method matplotlib.pyplot.contour? This accepts a numpy.meshgrid, documentation is linked below:

https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.contour.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM