繁体   English   中英

pyplot图的add_axes将新轴附加到具有相同位置的旧轴

[英]add_axes to pyplot figure attaches new axis to old axis with same position

当我尝试在原先放置另一个轴的同一位置上使用fig.add_axes将轴添加到pyplot图形中时,pyplot只是引用了旧轴。

我有一个要求在哪里制作数字,然后可以添加轴。 根据要求,添加不同的轴。

我尝试将ax.set_position的“哪个”参数设置为“两者”,“活动”和“原始”,但是没有一个参数。

import matplotlib.pyplot as plt

fig = plt.figure()

ax1 = fig.add_axes([0.07, 0.1, 0.88, 0.2])
ax1.set_position([0.07, 0.3, 0.88, 0.2], which='active')
ax2 = fig.add_axes([0.07, 0.1, 0.88, 0.2])
ax2.set_position([0.07, 0.3, 0.88, 0.5])

# When trying to set position of either figure it simply moves them both
# as ax2 is a reference to ax1
ax1.set_position([0.07, 0.1, 0.88, 0.2])

我如何获得它,例如ax2是未引用ax1的独立对象?

我自己找到了一个答案-这是万一其他人都面临类似问题的情况。

该问题将在下一版的matplotlib中修复,但与此同时,可以通过为每个轴指定标签来绕过此问题。

import matplotlib.pyplot as plt
fig = plt.figure()

ax1 = fig.add_axes([0.07, 0.1, 0.88, 0.2], label='no_1')
ax1.set_position([0.07, 0.3, 0.88, 0.2], which='both')
ax2 = fig.add_axes([0.07, 0.1, 0.88, 0.2], projection=None)
ax2.set_position([0.07, 0.1, 0.88, 0.5], label='no_2')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM