如何增加Matplotlib底部的空间?

发布于 2025-02-12 13:41:58 字数 1328 浏览 0 评论 0原文

我使用以下命令在matplotlib中创建一个图:

    fig = plt.figure()
    ax = plt.axes() 
    ax.plot ( xdata, ydata )
    my_cmap = cm.seismic
    ax.tick_params ( axis='x', labelsize=16 )
    ax.tick_params ( axis='y', labelsize=16 )
    sm = plt.cm.ScalarMappable ( cmap=my_cmap, norm=plt.Normalize(vmin=0, vmax=1) )
    cbar = plt.colorbar(sm, orientation='vertical') 
    cbar.set_ticks ( [0, 1] )
    cbar.set_ticklabels( ["Poorest", "Best"] ) 
    cbar.ax.tick_params(labelsize=14)
    cbar.ax.set_ylabel ("Quality of solvent", fontsize=18, rotation=270)
    ax.set_xscale('log')
    ax.set_xlabel ( "Temperature (reduced)", fontsize=18) 
    ax.set_ylabel ( "$\\xi$", fontsize=18)
    ax.yaxis.set_major_locator(matplotlib.ticker.MaxNLocator(11))
    ax.set_yticks (np.linspace(0, 1, 11)) 
    fig.tight_layout ()
    plt.savefig   ( "DOP_"+str(dop)+"_parameter.png", dpi=1000)

我将获得以下图像:

这篇文章:在matplotlib?中的图形底部,建议我使用plt.tight_layout(),但显然不起作用。如何将额外的空间添加到图的底部,同时保持0.0至1.0?

I am creating a plot in matplotlib using the following commands:

    fig = plt.figure()
    ax = plt.axes() 
    ax.plot ( xdata, ydata )
    my_cmap = cm.seismic
    ax.tick_params ( axis='x', labelsize=16 )
    ax.tick_params ( axis='y', labelsize=16 )
    sm = plt.cm.ScalarMappable ( cmap=my_cmap, norm=plt.Normalize(vmin=0, vmax=1) )
    cbar = plt.colorbar(sm, orientation='vertical') 
    cbar.set_ticks ( [0, 1] )
    cbar.set_ticklabels( ["Poorest", "Best"] ) 
    cbar.ax.tick_params(labelsize=14)
    cbar.ax.set_ylabel ("Quality of solvent", fontsize=18, rotation=270)
    ax.set_xscale('log')
    ax.set_xlabel ( "Temperature (reduced)", fontsize=18) 
    ax.set_ylabel ( "$\\xi
quot;, fontsize=18)
    ax.yaxis.set_major_locator(matplotlib.ticker.MaxNLocator(11))
    ax.set_yticks (np.linspace(0, 1, 11)) 
    fig.tight_layout ()
    plt.savefig   ( "DOP_"+str(dop)+"_parameter.png", dpi=1000)

I am getting the following image:
enter image description here

This post: How do I extend the margin at the bottom of a figure in Matplotlib? suggested I use plt.tight_layout(), but that evidently did not work. How do I add additional space to the bottom of the plot, while maintaining the yrange from 0.0 to 1.0?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文