[英]Matplotlib: Plotting of 3D data on a Cartesian coordinate system, with 1D Arrays (Python)
Good Afternoon All,大家下午好,
I'm attempting to create a contour map of surface elevation by using drilling data from a mineral exploration programme.我正在尝试使用矿物勘探程序中的钻孔数据创建地表高程等高线图。 I am new to programming, any feedback would be welcomed!
我是编程新手,欢迎任何反馈!
Each drill hole has a:每个钻孔都有一个:
An excerpt of the data is as follows:数据摘录如下:
Methodology方法
I broke the work down into two steps.我把工作分成两步。
1) Checking that the data plots in the correct area 1) 检查数据是否绘制在正确的区域
I used pandas
to extract the co-ordinates of each drilling hole from the csv file, and plotted the data using plt.scatter
from matplotlib
.我使用
pandas
从 csv 文件中提取每个钻孔的坐标,并使用来自matplotlib
plt.scatter
绘制数据。
This is my output.这是我的输出。 So far it works, so now I want to plot the 3D (z axis) data.
到目前为止它有效,所以现在我想绘制 3D(z 轴)数据。
2) Plotting of Surface_Elevation (z axis) 2)绘制Surface_Elevation(z轴)
This is where I am having problems.这是我遇到问题的地方。 I've read through several contouring guides for matplotlib which is dependent on
plt.contour
.我已经阅读了几个依赖于
plt.contour
matplotlib 轮廓指南。 The issue is that this function wants a 2D array, and the data that I want to contour is 1D.问题是这个函数需要一个二维数组,而我想要绘制的数据是一维的。 Am I missing something here?
我在这里错过了什么吗?
My attempt我的尝试
import matplotlib.pyplot as plt # plot data
import pandas as pd # extract data from csv
# access csv and assign as a variable
dataset = pd.read_csv('spreadsheet.csv')
# x_axis values extracted and converted to a list from the csv
x_axis = list(dataset["Orig_East"])
# y_axis values extracted and converted to a list from the csv
y_axis = list(dataset["Orig_North"])
# z_axis values extracted and converted to a list from the csv
z_axis = list(dataset["Surface_Elevation"])
plt.contour(x_axis, y_axis, z_axis, colors='black');
plt.ticklabel_format(useOffset=False, style='plain') # remove exponential axis labels
plt.xlabel('Easting') # label x axis
plt.ylabel('Northing') # label y axis
plt.title('Surface Elevation') # label plot
# plot graph
plt.show()
A possible solution is to encode the elevation of each point into the color of the scatter marker.一种可能的解决方案是将每个点的高程编码为散点标记的颜色。 This can be done by calling
plt.scatter(x, y, c=z)
you can also specify a desired cmap
, see the documentation .这可以通过调用
plt.scatter(x, y, c=z)
来完成,您还可以指定所需的cmap
,请参阅文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.