
one of our tests is failing because the output image is sometimes a slightly different size. on linux it is 579×517 pixels and on windows it is 582×520 pixels. i have checked the versions of matplotlib and pandas and they are the same. there are slight differences in matplotlib.rcparams; i’ve tried changing the parameters that look relevant, but it didn’t help.
Is it because the display size is slightly different on the two machines? If I set dpi=99.99 on the savefig on the Windows machine, the output size is 579×517 pixels. I don’t want to change this in the application though as it is a bit of a hack just to fix a failing test.
This is the plot function we’re using, percentages is a pandas dataframe.
存了个图
视频图片解析/字幕/剪辑,视频高清保存/图片源图提取
17 查看详情
代码语言:javascript代码运行次数:0运行复制
def plot_and_save(percentages, output_directory, filename, title, legend, x_label, y_label, font_size=16): """Plot data and save figure to file.""" matplotlib.rcParams['font.size'] = font_size ax1 = percentages.plot.bar(color=['#484D7A', '#F6A124']) ax1.grid(which='major', axis='y', color='#4A4A49', alpha=0.1) ax1.set_axisbelow(True) # Puts gridlines below the bars ax1.set(xlabel=x_label, ylabel=y_label, title=title) ax1.legend(legend, framealpha=1) output_path = os.path.join(output_directory, filename) plt.savefig(output_path, bbox_inches='tight') plt.close()来源:https://stackoverflow.com/questions/67515453/how-to-save-matplotlib-figures-the-same-size-on-different-operating-systems
以上就是如何在不同的操作系统里保存同样大小的matplotlib图片?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/377172.html
微信扫一扫
支付宝扫一扫