【问题标题】:Difficulty in understanding matplotlib axes难以理解 matplotlib 轴
【发布时间】:2018-05-13 10:12:10
【问题描述】:

我有关注数据 年 数组([1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011])

物理科学 数组([13.8, 14.9, 14.8, 16.5, 18.2, 19.1, 20. , 21.3, 22.5, 23.7, 24.6, 25.7, 27.3, 27.6, 28. , 27.5, 28.4, 30.4, 29.7, 31.3, 31.6, 32.6, 32.6, 33.6, 34.8, 35.9, 37.3, 38.3, 39.7, 40.2, 41., 42.2, 41.1, 41.7、42.1、41.6、40.8、40.7、40.7、40.7、40.2、40.1])

计算机科学 数组([13.6, 13.6, 14.9, 16.4, 18.9, 19.8, 23.9, 25.7, 28.1, 30.2, 32.5, 34.8、36.3、37.1、36.8、35.7、34.7、32.4、30.8、29.9、29.4、28.7、 28.2, 28.5, 28.5, 27.5, 27.1, 26.8, 27. , 28.1, 27.7, 27.6, 27. , 25.1、22.2、20.6、18.6、17.6、17.8、18.1、17.6、18.2])

当我运行以下代码时

# Create plot axes for the first line plot
plt.axes([.05,.05,.425,.9])

# Plot in blue the % of degrees awarded to women in the Physical Sciences
plt.plot(year, physical_sciences, color='blue')

# Create plot axes for the second line plot
plt.axes([.525,.05,.425,.9])

# Plot in red the % of degrees awarded to women in Computer Science
plt.plot(year, computer_science, color='red')

# Display the plot
plt.show()

Graph generated

我的问题是为什么轴指定的坐标不在 x 轴上,或者它是否以其他方式工作。 谢谢你的帮助。

【问题讨论】:

    标签: python matplotlib axes


    【解决方案1】:

    matplotlib documentation of pyplot.axes可以看出axes的参数可能是一个

    浮点数的四元组rect = [left, bottom, width, height]。使用当前图窗上的 add_axes 添加了一个新轴,其尺寸为 rect,采用标准化的 (0, 1) 单位。

    这意味着plt.axes([.05,.05,.425,.9]) 添加了一个坐标区,其左下角为(.05,.05),宽度为.425,高度为.9。粗略地说,它跨越了图的左侧。

    请注意,大多数情况下根本不需要指定轴的位置。只需并排创建两个子图就足够了。

    # Create plot axes for the first line plot
    plt.subplot(121)
    
    # Plot in blue the % of degrees awarded to women in the Physical Sciences
    plt.plot(year, physical_sciences, color='blue')
    
    # Create plot axes for the second line plot
    plt.subplot(122)
    
    # Plot in red the % of degrees awarded to women in Computer Science
    plt.plot(year, computer_science, color='red')
    
    # Display the plot
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2010-10-28
      • 2014-11-15
      • 2014-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多