matplotlib中的最后一个图形标记未完全显示 [英] Last graph marker in matplotlib not showing fully

查看:36
本文介绍了matplotlib中的最后一个图形标记未完全显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new to matplotlib. My graph in matplotlib doesn't show the last marker fully. I've tried increasing the figure size and nothing changes. I need to extend the figure so that it shows the last marker and also extend the line past the marker. Here's my code:

    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 轴?)

您要边距 文档

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

另见添加当图与图的边缘相对时的边距

matplotlib 1.3.x将包含 rcParam axes.xmargin axes.ymargin 来设置非零边距(它的代码已经在 master 中).

matplotlib 1.3.x will include the rcParam values axes.xmargin and axes.ymargin to set a none-zero margin (code for it is in master already).

这篇关于matplotlib中的最后一个图形标记未完全显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆