填充等高线图顶部的绘图点添加了大量空白sp

2024-03-29 11:49:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下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

似乎只需添加一个点(在原始轴范围内)就会在半径轴上拧紧轴范围。在

这是设计的还是错误的?你建议怎么解决它?我需要手动调整轴范围吗,还是有办法停止额外的绘图命令?在


Tags: lenplotnpfigaxarrayvaluescb
1条回答
网友
1楼 · 发布于 2024-03-29 11:49:55

如果未明确指定轴自动缩放模式,plot将使用“loose”自动缩放,contourf将使用“tight”自动缩放。在

对于非极轴也是如此。E、 g

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')或{}。在
  2. scalex=False和{}作为plot的关键字参数传入。在
  3. 手动设置轴限制。在

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

相关问题 更多 >