注意
前往結尾以下載完整範例程式碼。
具有固定物理尺寸的軸#
請注意,這可以使用主程式庫來完成,用於尺寸不會變更的圖形上的軸:一次新增單個軸
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import Divider, Size
fig = plt.figure(figsize=(6, 6))
# The first items are for padding and the second items are for the Axes.
# sizes are in inch.
h = [Size.Fixed(1.0), Size.Fixed(4.5)]
v = [Size.Fixed(0.7), Size.Fixed(5.)]
divider = Divider(fig, (0, 0, 1, 1), h, v, aspect=False)
# The width and height of the rectangle are ignored.
ax = fig.add_axes(divider.get_position(),
axes_locator=divider.new_locator(nx=1, ny=1))
ax.plot([1, 2, 3])

fig = plt.figure(figsize=(6, 6))
# The first & third items are for padding and the second items are for the
# Axes. Sizes are in inches.
h = [Size.Fixed(1.0), Size.Scaled(1.), Size.Fixed(.2)]
v = [Size.Fixed(0.7), Size.Scaled(1.), Size.Fixed(.5)]
divider = Divider(fig, (0, 0, 1, 1), h, v, aspect=False)
# The width and height of the rectangle are ignored.
ax = fig.add_axes(divider.get_position(),
axes_locator=divider.new_locator(nx=1, ny=1))
ax.plot([1, 2, 3])
plt.show()

腳本總執行時間:(0 分鐘 1.208 秒)