【问题标题】:Figure dimensions, matplotlib, python3.4图尺寸,matplotlib,python3.4
【发布时间】:2014-12-07 10:37:19
【问题描述】:
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt

def fig1():
    x = np.arange(-5,5,0.01)
    f1 = lambda x: x**2 +x -6
    f2 = lambda x: x*0
    plt.plot(x, f1(x))
    plt.plot(x, f2(x),'black')
    axes = plt.gca()
    axes.set_ylim([-10,10])
    axes.set_xlim([-5,5])
    plt.show()    

我怎样才能强制这个数字进入特定的尺寸?目前它显示在一个矩形平面上,但我想强制尺寸严格为 n x n。

【问题讨论】:

    标签: python-3.x numpy matplotlib


    【解决方案1】:

    如果您想将pyplot 强制设置为手动指定的大小,可以使用matplotlib.figure module 中的figsize 参数来实现

    以下示例中的两个尺寸示例,一个矩形和一个正方形尺寸5x5 and 5x8

    import numpy as np
    import matplotlib.pyplot as plt
    
    def fig1():
        x = np.arange(-5,5,0.01)
        f1 = lambda x: x**2 +x -6
        f2 = lambda x: x*0
        fig = plt.figure(figsize=(5,8)) # IT IS HERE THAT WE SPECIFY THE FIGSIZE
        ax = fig.add_subplot(111)
        ax.plot(x, f1(x))
        ax.plot(x, f2(x),'black')
        ax.set_ylim([-10,10])
        ax.set_xlim([-5,5])
        plt.show()
    

    当我们使用 5x5 时,我们会得到这样的结果

    当我们使用5x8 时,我们会得到这样的结果:

    【讨论】:

      猜你喜欢
      • 2016-06-22
      • 2011-07-16
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 1970-01-01
      • 2019-05-14
      • 2020-12-25
      • 1970-01-01
      相关资源
      最近更新 更多