如何将一个轴添加到另一个轴的外部,并将其作为一个整体保持在图中? legend
并且colorbar
两者都具有这种能力,但是以相当复杂(对我来说,很难重现)的方式实现。
问问题
55 次
1 回答
0
您可以使用 subplots 命令来实现这一点,这可以很简单py.subplot(2,2,1)
,前两个数字描述地块的几何形状 (2x2),第三个是当前地块编号。一般来说,最好是明确的,如下例所示
import pylab as py
# Make some data
x = py.linspace(0,10,1000)
cos_x = py.cos(x)
sin_x = py.sin(x)
# Initiate a figure, there are other options in addition to figsize
fig = py.figure(figsize=(6,6))
# Plot the first set of data on ax1
ax1 = fig.add_subplot(2,1,1)
ax1.plot(x,sin_x)
# Plot the second set of data on ax2
ax2 = fig.add_subplot(2,1,2)
ax2.plot(x,cos_x)
# This final line can be used to adjust the subplots, if uncommentted it will remove all white space
#fig.subplots_adjust(left=0.13, right=0.9, top=0.9, bottom=0.12,hspace=0.0,wspace=0.0)
请注意,这意味着py.xlabel
由于您有两个轴,因此可能无法按预期工作。相反,您需要指定ax1.set_xlabel("..")
这会使代码更易于阅读。
可以在此处找到更多示例。
于 2013-05-07T09:20:50.163 回答