在GIS预处理器中实现(出色的matplotlib)轮廓绘制时,结果有些不理想[请参见所附图像以获取参考]。
结果不是理想的展示折线段(橙色的圆圈区域),而是闭合的多边形环(绿色突出显示的路径)。
我对游戏逻辑的最佳推断;在附加图像中从左到右,轮廓级别正在降低。闭合的循环表明matplotlib.pyplot.contours()正在将所有值合并到所述级别的范围内-因此,闭合循环了吗?
目的是使这些大致垂直的轮廓线水平在所述形状的边界处截止。考虑到这些轮廓的路径是用pyplot的另一种方法来抓取并绘制的-内置的遮罩和裁剪似乎可能不适用。
也许在最初的轮廓创建过程中我忽略了文档中的一个论点-还是满足描述需求的其他方法?
感谢您提供线索或智慧。
电流输入
(meshXList,meshYList和valueZList是位于所示多边形内的各向同性网格质心坐标)
X = np.array(self.meshXList).reshape(self.numRows,self.numCols)
Y = np.array(self.meshYList).reshape(self.numRows,self.numCols)
Z = np.array(self.valueZList).reshape(self.numRows,self.numCols)
conIntrv = float(self.conIntNum.text())
minCon,maxCon = float(self.minConLineNum.text()),float(self.maxConLineNum.text())
numCon = int((maxCon-minCon)/conIntrv)
levels = np.linspace(minCon,maxCon,numCon)
contours = plt.contour(X,Y,Z,levels,antialiased=True)
conCollect = contours.collections
rawContourLines = []
for lineIdx, line in enumerate(conCollect):
lineStrings = []
for path in line.get_paths():
if len(path.vertices)>1:
lineStrings.append(path.vertices)
rawContourLines.append(lineStrings)
@ tom10最衷心地暗示着对我来说应该是显而易见的。附加图像中的灰色区域包含在meshXList,meshYList和valueZList中;尽管未在GIS程序中选择显示。
理解valueZList不需要数字值(使用-999.99999999999),而是可以合并{None},这表明该问题的解决方案非常简单:
emptValue = None
self.valueZList = [emptValue]*len(self.meshXList)
with open(valueFile, "r") as valueInput:
reader = csv.reader(valueInput)
for idx,row in enumerate(reader):
if idx==0: self.valueType = row[1]
if idx>0:
holdingIdx = int(row[0])
holdingVal = float(row[1])
if '888.88' in holdingVal or '777.77' in holdingVal:
self.valueZList[holdingIdx] = emptValue
else:
self.valueZList[holdingIdx]=holdingVal
if holdingVal<minValue: minValue = holdingVal
if holdingVal>maxValue: maxValue = holdingVal
Horray的“无类型”。
一种方法是将边界外的区域设置为None
。因此,修改标准示例以提供“开放”轮廓:
import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
matplotlib.rcParams['xtick.direction'] = 'out'
matplotlib.rcParams['ytick.direction'] = 'out'
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)
Z[X<-1] = None
Z[X>2] = None
plt.figure()
CS = plt.contour(X, Y, Z, levels=np.arange(-.5, 2, .5))
plt.clabel(CS, inline=1, fontsize=10)
plt.title('Simplest default with labels')
plt.show()
或者,更有趣(使用,Z[X*X+(Y-1)**2>3.] = None
):
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句