gpt4 book ai didi

python - 填充等高线图顶部的绘图点增加了大量空白

转载 作者:太空狗 更新时间:2023-10-30 02:49:11 24 4
gpt4 key购买 nike

我有以下 Python 代码,我用它来绘制填充等高线图:

  def plot_polar_contour(values, azimuths, zeniths):
theta = np.radians(azimuths)
zeniths = np.array(zeniths)

values = np.array(values)
values = values.reshape(len(azimuths), len(zeniths))

r, theta = np.meshgrid(zeniths, np.radians(azimuths))
fig, ax = subplots(subplot_kw=dict(projection='polar'))
ax.set_theta_zero_location("N")
ax.set_theta_direction(-1)
cax = ax.contourf(theta, r, values, 30)
autumn()
cb = fig.colorbar(cax)
cb.set_label("Pixel reflectance")
show()

这给了我一个像这样的情节:

enter image description here

但是,当我在 show() 之前添加行 ax.plot(0, 30, 'p') 时,我得到以下信息:

enter image description here

似乎只是添加一个点(完全在原始轴范围内)就搞砸了半径轴上的轴范围。

这是设计使然还是错误?你会建议做什么来解决它?我是否需要手动调整轴范围,或者是否有办法停止执行此操作的额外绘图命令?

最佳答案

如果轴自动缩放模式未明确指定,plot 将使用“松散”自动缩放,contourf 将使用“紧”自动缩放。

非极轴也会发生同样的事情。例如

import matplotlib.pyplot as plt
import numpy as np

plt.imshow(np.random.random((10,10)))
plt.plot([7], [7], 'ro')
plt.show()

您有多种选择。

  1. 在代码中的某个点显式调用 ax.axis('image')ax.axis('tight')
  2. scalex=Falsescaley=False 作为关键字参数传递给 plot
  3. 手动设置轴限制。

最简单和最易读的是直接显式调用 ax.axis('tight'),i.m.o.

关于python - 填充等高线图顶部的绘图点增加了大量空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9380069/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com