问题描述
大家晚上好
我已经取得了一些进步,但是更多的是“向前迈出,向后迈出两步”类型的事情。
我已经在分散/等高线图(matplotlib)
上绘制了钻井数据。散点图显示了每个钻孔的位置,而等高线图则插入了一条古老河流的基岩标高。
问题是我无法在注释弹出窗口上显示基岩高程值(z轴)数据。用mplcursors
构造的注释显示轮廓的行号,但不显示用于构造基岩高程的插值z值。
我认为,通过输入zi值(从zi = interpolator(Xi,Yi)
生成的mask.array),可以将z值显示为基岩标高,而不是等高线号。
肯定有我缺少的东西。知道为什么这行不通吗?
这是我当前的输出:
"""
# -----------------------
# Import libraries
# -----------------------
"""
import matplotlib.pyplot as plt
import matplotlib.tri as tri
import numpy as np
import pandas as pd
from mpldatacursor import datacursor
import mplcursors
"""
# -----------------------
# Access and extract data from spreadsheet
# -----------------------
"""
# access csv and assign as a variable
dataset = pd.read_csv('Stoffdraai.csv')
# x_axis values extracted and converted to a list from the csv
x = list(dataset["Easting"])
# y_axis values extracted and converted to a list from the csv
y = list(dataset["northing"])
# z_axis values extracted and converted to a list from the csv
z = list(dataset["Bdr_Elevat"])
ngridx = 1000
ngridy = 2000
fig,(ax1) = plt.subplots()
"""
# -----------------------
# Interpolation on a grid
# -----------------------
# A contour plot of irregularly spaced data coordinates
# via interpolation on a grid.
"""
# Create grid values first.
xi = np.linspace(-2.1,2.1,ngridx)
yi = np.linspace(-2.1,ngridy)
# Linearly interpolate the data (x,y) on a grid defined by (xi,yi).
triang = tri.Triangulation(x,y)
interpolator = tri.LinearTriInterpolator(triang,z)
Xi,Yi = np.meshgrid(xi,yi)
zi = interpolator(Xi,Yi)
"""
# ----------
# Tricontour
# ----------
"""
cf = ax1.tricontour(x,y,z,levels=36,linewidths=0.25,colors='k') #
cntr2 = ax1.tricontourf(x,cmap="terrain") # Colour Bar has colour scheme RdBu_r
"""
# ----------
# Plot Setup
# ----------
"""
fig.colorbar(cntr2,ax=ax1)
ax1.set_title('bedrock Elevation')
ax1.plot(x,'ko',ms=1.5)
ax1.set(xlim=(min(x) - 100,max(x) + 100),ylim=(min(y) - 100,max(y) + 100)) # Sets up the grid
# Superficial Graph Formatting
ax1.set_title('bedrock Elevation') # Defines the plot name
plt.ylabel('northing') # y axis label
plt.xlabel('Easting') # x axis label
ax1.ticklabel_format(uSEOffset=False,style='plain')
plt.subplots_adjust(hspace=1)
"""
# ----------
# Map cursor
# ----------
Map cursor currently displays x and y axis values on the drill holes and the interpolated contour lines
Uses mpldatacursors
"""
cursor = mplcursors.cursor()
#The function below appears to extract the z value,not from the interpolated z values,the number of contour lines.
@cursor.connect("add")
def on_add(sel):
ann = sel.annotation.
ann.set_text("{}\nbedrock Elevation={:.0f}".format(
ann.get_text(),cf.cvalues[cf.collections.index(sel.artist)]))
plt.show()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)