matplotlib 中的最后一个图形标记未完全显示

2023-12-12

我是 matplotlib 的新手。我在 matplotlib 中的图表没有完全显示最后一个标记。我尝试过增加图形大小,但没有任何变化。我需要扩展图形,以便它显示最后一个标记,并将线条延伸到标记之外。这是我的代码:

    import numpy as np
    import matplotlib.pyplot as plt

    x = np.array([1,2,5,10,15,20])
    y = np.array([0.049,0.080,0.123,0.166,0.209,0.335])

    A = np.vstack([x, np.ones(len(x))]).T
    m, c = np.linalg.lstsq(A, y)[0]

    x = np.array([0,1,2,5,10,15,20])
    y = np.array([c,0.049,0.080,0.123,0.166,0.209,0.335])

    plt.plot(x, y, 'r*', label='Original data', markersize=7)
    plt.plot(x, m*x + c, 'b', label='Fitted line')
    fig = plt.figure(1)
    fig.set_size_inches(9,8)
    fig.suptitle('THE GRAPH OF ABSORBANCE AGAINST CONCENTRATION',fontsize=20)
    plt.xlabel('CONCENTRATION',fontsize=15)
    plt.ylabel('ABSORBANCE',fontsize=15)
    plt.grid()
    fig.savefig('graph.jpg')

非常感谢您的帮助。


(大部分复制自如何在matplotlib中自动缩放y轴?)

你要margins doc

ex

ax.margins(y=.1, x=.1)

另请参阅当绘图靠近图形边缘时添加边距

matplotlib1.3.x 将包括rcParam values axes.xmargin and axes.ymargin设置非零边距(其代码已在 master 中)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

matplotlib 中的最后一个图形标记未完全显示 的相关文章

随机推荐