python - 为什么保存我的 matplotlib 图像时,标题没有出现?
问题描述
我做了一个阴谋。我设定了自己的传奇。当我保存图像时,标题没有出现。我不知道为什么。
这是我的代码:
ax = plt.gca()
df1_MAXN.plot(kind = 'line', y = 'MemUsed', ax=ax, legend=True, label='MAXN')
df1_MAXQ.plot(kind = 'line', y = 'MemUsed', color='red', ax=ax, legend=True, label='MAXQ')
#Annotate the max values using the data coordenates
ax.annotate('3284.97',xy=(70000, 3284.97), xycoords='data')
ax.annotate('2903.8',xy=(70000, 2903.8), xycoords='data')
#Remove top and right axis
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
#The legend
myLegend=plt.legend(bbox_to_anchor=(0., 1.1, 1., .102), prop ={'size':10}, loc='center',frameon=False, ncol=2, title=r'TX2 (GPU) USED MEMORY - I_V1')
myLegend.get_title().set_fontsize('14')
ax.set_xlabel("NUMBER OF INFERENCES")
ax.set_ylabel("USED MEMORY (MB)")
plt.savefig('Memory_Iv1_TX2.png', dpi = 1000)
plt.show()
应该是这样的:
解决方案
我刚刚找到了答案。我补充说bbox_inches='tight
。现在标题出现在保存的图像中:)
#Save image removing the whitespace around it
plt.savefig('Memory_Iv1_TX2.png', bbox_inches='tight', dpi = 1000)
plt.show()
推荐阅读
- c++ - 在 C++ 模板中获取指针的目标类型
- python - 刷新的 Pygame 窗口将 Sprite 以前的位置显示为背景屏幕的一部分
- javascript - 在页面加载时多次调用 React Fetch API
- c++ - 如何从函数返回具有多个值的数组?C++
- kubernetes - GKE 中同时运行的 Pod 数量的限制因素是什么?
- sql - 是否可以测试列的存在,然后根据列是否存在来选择操作?
- python - 将字典合并到数据框,其中两个字典值都是标量
- html - React.js(参考错误:React 未定义)
- c++ - error: request for memver '' in '', which is of non-class type 'int*'//使用void函数内部的方法打印结构中的信息
- tableau-api - 是否可以使用 tableauserverclient 更改 twb 文件的数据源?