python 中 plt.contour 的轮廓线错误 3
Contour line error with plt.contour in python 3
我正在使用 matplotlib 在 python 3 中绘制等高线图,但我得到了一个奇怪的结果。起初,我使用的是 plt.contourf,并注意到数据中有一个我知道不应该存在的奇怪的南北线性伪影(我使用了模拟数据)。所以我把plt.contourf改成了plt.contour,问题好像是部分边缘轮廓因为某些原因变形了(见图)。
不幸的是,我很难通过我的代码的简单版本,因为这是一个基于 GUI 的大型应用程序的一部分。不过,这就是我正在做的事情。
#grid the x,y,z data so it can be used in the contouring
self.beta_zi =
#This is matplot griddata, not the scipy.interpolate.griddata
griddata(self.output_df['x'].values,self.output_df['y'].values,
self.output_df['Beta'].values,
self.cont_grid_x,
self.cont_grid_y,
interp='linear')
#call to the contour itself
self.beta_contour=self.beta_cont_ax.contour(self.cont_grid_x,self.cont_grid_y,
self.beta_zi,
levels=np.linspace(start=0,stop=1, num=11, endpoint=True),
cmap=cm.get_cmap(self.user_beta_cmap.get()))
这似乎是一个基于边缘的简单问题。有没有人见过这个可以提供帮助。我使用的是 TK 后端,它与我编写的基于 tkinter 的 GUI 配合使用效果更好。
更新:我也尝试更改为 scipy.interpolate.griddata 因为 matplot 的网格数据已被弃用,但问题是相同的并且仍然存在,所以它必须与实际的等高线绘图功能有关。
我发现问题与我如何解释轮廓和网格数据的输入有关。
plt.contour and matplot.griddata takes
x = x location of sample data
y = y location of sample data
z = height or z value of sample data
xi = locations of x tick marks on grid
zi = locations of y ticks marks on grid
通常 xi 和 yi 是每个网格节点的所有位置,这是我提供的,但在这种情况下,您只需要每个轴上的唯一刻度线。
多亏了这个post我弄明白了。
Matplotlib contour from xyz data: griddata invalid index
我正在使用 matplotlib 在 python 3 中绘制等高线图,但我得到了一个奇怪的结果。起初,我使用的是 plt.contourf,并注意到数据中有一个我知道不应该存在的奇怪的南北线性伪影(我使用了模拟数据)。所以我把plt.contourf改成了plt.contour,问题好像是部分边缘轮廓因为某些原因变形了(见图)。
不幸的是,我很难通过我的代码的简单版本,因为这是一个基于 GUI 的大型应用程序的一部分。不过,这就是我正在做的事情。
#grid the x,y,z data so it can be used in the contouring
self.beta_zi =
#This is matplot griddata, not the scipy.interpolate.griddata
griddata(self.output_df['x'].values,self.output_df['y'].values,
self.output_df['Beta'].values,
self.cont_grid_x,
self.cont_grid_y,
interp='linear')
#call to the contour itself
self.beta_contour=self.beta_cont_ax.contour(self.cont_grid_x,self.cont_grid_y,
self.beta_zi,
levels=np.linspace(start=0,stop=1, num=11, endpoint=True),
cmap=cm.get_cmap(self.user_beta_cmap.get()))
这似乎是一个基于边缘的简单问题。有没有人见过这个可以提供帮助。我使用的是 TK 后端,它与我编写的基于 tkinter 的 GUI 配合使用效果更好。
更新:我也尝试更改为 scipy.interpolate.griddata 因为 matplot 的网格数据已被弃用,但问题是相同的并且仍然存在,所以它必须与实际的等高线绘图功能有关。
我发现问题与我如何解释轮廓和网格数据的输入有关。
plt.contour and matplot.griddata takes
x = x location of sample data
y = y location of sample data
z = height or z value of sample data
xi = locations of x tick marks on grid
zi = locations of y ticks marks on grid
通常 xi 和 yi 是每个网格节点的所有位置,这是我提供的,但在这种情况下,您只需要每个轴上的唯一刻度线。
多亏了这个post我弄明白了。
Matplotlib contour from xyz data: griddata invalid index