我有一个类似于这里发布的问题.不同之处在于,当我绘制两个通过sharex和sharey属性共享轴的子图时,我在绘图区域内得到了不需要的空白区域.设置后,白色空间仍然存在autoscale(False).例如,使用与上述帖子的答案类似的代码:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(2, 1, 1)
ax.imshow(np.random.random((10,10)))
ax.autoscale(False)
ax2 = fig.add_subplot(2, 1, 2, sharex=ax, sharey=ax) # adding sharex and sharey
ax2.imshow(np.random.random((10,10)))
ax2.autoscale(False)
plt.show()
Run Code Online (Sandbox Code Playgroud)
得到这个图像.
我也曾尝试ax.set_xlim(0, 10)和ax.set_xbound(0, 10)按照建议在这里,但无济于事.我怎样才能摆脱多余的空白?任何想法,将不胜感激.
我使用matplotib的Axes API来绘制一些数字.我绘制的一条线代表理论预期线.它在原始y和x限制之外没有任何意义.我想要的是matlplotlib在自动缩放限制时忽略它.我以前做的是检查当前限制是什么,然后绘制并重置限制.问题在于,当我绘制第三个图时,限制会与理论线一起重新计算,这真的会扩展图形.
# Boilerplate
from matplotlib.figure import Figure
from matplotlib.backends.backend_pdf import FigureCanvasPdf
from numpy import sin, linspace
fig = Figure()
ax = fig.add_subplot(1,1,1)
x1 = linspace(-1,1,100)
ax.plot(x1, sin(x1))
ax.plot(x1, 3*sin(x1))
# I wish matplotlib would not consider the second plot when rescaling
ax.plot(x1, sin(x1/2.0))
# But would consider the first and last
canvas_pdf = FigureCanvasPdf(fig)
canvas_pdf.print_figure("test.pdf")
Run Code Online (Sandbox Code Playgroud) 我有以下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()
Run Code Online (Sandbox Code Playgroud)
这给了我一个情节:

但是,当我ax.plot(0, 30, 'p')在show()获得以下内容之前添加该行时:

似乎只添加一个点(在原始轴范围内)就会在半径轴上拧紧轴范围.
这是设计,还是这个bug?你有什么建议去修理它?我是否需要手动调整轴范围,或者是否有办法停止额外的绘图命令?