
one of our tests is failing because the output image is sometimes a slightly different size. on linux it is 579x517 pixels and on windows it is 582x520 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 579x517 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.
这是一款用于静静设计网站后台管理界面模板,也可以用于管理系统或其它通用后台界面。这款后台模板的宗旨是,页面基本没有过多的交互效果,简洁粗暴的同时带来的是界面加载速度的提升或操作便捷性的增加。2个css文件不超过20k,图标采用的是字体图标,图标素材都来自于icomoon网站,没有任何图片。页面整体采用扁平化处理,布局更趋向于暴露内容的本质,页面块之间的留白更多,字体更大,配色更单一,在form表单
403
<pre class="brush:php;toolbar:false;">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图片?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号