【问题标题】:How to changes axes size within a fix figure in python?如何在 python 的固定图中更改轴大小?
【发布时间】:2019-08-16 14:07:07
【问题描述】:

这段代码:

import matplotlib.pyplot as plt
fig = plt.figure(facecolor=(1, 0, 0, .1))
ax = fig.add_subplot(1,1,1) 
plt.show()

为图形输出一个粉红色的框架,其中一个白色的框架用于轴对象。现在,是否可以在不更改图形大小的情况下更改图形中轴对象的大小?

【问题讨论】:

    标签: python axes


    【解决方案1】:

    试试这个代码,看看这是否是你想要的。您可以更改函数内部给出的固定大小值。

    import matplotlib.pyplot as plt
    from mpl_toolkits.axes_grid1 import Divider, Size
    from mpl_toolkits.axes_grid1.mpl_axes import Axes
    
    
    def demo_fixed_size_axes():
        fig = plt.figure(facecolor=(1, 0, 0, .1))
    
    
        # 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, 0.0, 1., 1.), h, v, aspect=False)
        # the width and height of the rectangle is ignored.
        ax = Axes(fig, divider.get_position())
        ax.set_axes_locator(divider.new_locator(nx=1, ny=1))
    
        fig.add_axes(ax)
    
        # ax.plot([1, 2, 3])
        plt.show()
    
    demo_fixed_size_axes()
    

    【讨论】:

      猜你喜欢
      • 2014-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-13
      • 1970-01-01
      • 1970-01-01
      • 2019-12-30
      • 2017-09-20
      相关资源
      最近更新 更多