我有一个x,y值的数组,我从等高线图得到,我想绘制这些值。因为它是一个圆圈内的圆圈,所以在圆圈之间绘制一条任意直线。有没有人知道删除这一行的方法?
我尝试对不起作用的点进行排序。我能想到删除这一行的唯一方法是手动将值移动到一个新数组并分别绘制它们。但是我有几个这样的情况,并且不希望筛选每个数据点。
#Plotted contours of a variable
cs1 = ax1.contourf(x,z,refl0,clevs)
#Get the contour lines for the 10th contour of the plot
p1 = cs1.collections[10].get_paths()[0]
v = p1.vertices
x1=v[:,0]
y1=v[:,1]
#Plot the contour lines
ax1 = plt.subplot(111)
ax1.plot(x1,y1)
这是一个通用示例代码
import numpy as np
from matplotlib import pyplot as plt
x= np.arange(-100,100,10)
y= np.arange(-100,100,10)
#Make a random circular function
xi,yi = np.meshgrid(x,y)
z= 2*xi +xi**2 -yi +yi**2
#This is the contour plot of the data
ax = plt.subplot(111)
clevs = np.arange(-100,110,10)*100
cs1 = ax.contourf(xi,yi,z,clevs)
plt.show()
#Get the contour lines for the 10th contour of the above plot
p1 = cs1.collections[11].get_paths()[0]
v = p1.vertices
x1=v[:,0]
y1=v[:,1]
#Plot the contour lines
ax1 = plt.subplot(111)
ax1.plot(x1,y1)
plt.show()
答案 0 :(得分:4)
如果目标是绘制两条特定的等高线,您只需选择相关的等级并对其进行contour
绘图:
import numpy as np
from matplotlib import pyplot as plt
x= np.arange(-100,100,10)
y= np.arange(-100,100,10)
#Make a random circular function
xi,yi = np.meshgrid(x,y)
z= 2*xi +xi**2 -yi +yi**2
ax = plt.subplot(111)
clevs = np.arange(-100,110,10)*100
cs1 = ax.contourf(xi,yi,z,clevs)
# chose level number 11 and 12 and draw them in black.
cs2 = ax.contour(xi,yi,z,clevs[11:13], colors="k")
plt.show()