简体   繁体   English

使用 plotnine 保存高分辨率图像

[英]Saving high-resolution images with plotnine

I'm trying to use plotnine to save a high-resolution png image.我正在尝试使用 plotnine 来保存高分辨率的 png 图像。

With a test dataset, this looks like:使用测试数据集,这看起来像:

from plotnine import *
import pandas as pd
import numpy as np

df = pd.DataFrame()
df['x'] = np.arange(0,10,0.01)
df['y'] = np.sin(df['x'])

p = ggplot(df, aes(x='x',y='y')) + labs(x='x', y='y') + geom_point(size=0.1)
p.save(filename = 'test3.png', height=5, width=5, units = 'in', dpi=1000)

This produces a low-resolution .png file containing my plot, which is not improved when I increase the specified dpi.这会生成一个包含我的绘图的低分辨率 .png 文件,当我增加指定的 dpi 时,它不会得到改善。

I've also tried saving with:我也尝试过保存:

ggsave(plot=p, filename='test.png', dpi=1000)

and replacing dpi=1000 with res=1000 .并将dpi=1000替换为res=1000 This produces identical low-resolution png files.这会产生相同的低分辨率 png 文件。

How can I save my plot at the resolution I want?如何以我想要的分辨率保存我的绘图?

Edit: This bug is resolved in plotnine version 0.3.0.编辑:此错误已在 plotnine 0.3.0 版中解决。 and the above code works correctly.并且上面的代码可以正常工作。

Since this still isn't answered and I just got directed here, too... 既然这还没有回答,我也被引导到这里......

According to @has2k1 (the author of plotnine ), this was a bug and is now resolved. 据@ has2k1(笔者plotnine ),这是一个错误,现在已经得到解决。 This commit looks like it might be the referenced fix. 此提交看起来可能是引用的修复。

To solve the issue, ensure you are using the git version or at least version 0.3.0 . 要解决此问题,请确保您使用的是git版本或至少使用0.3.0版

There is also the possibility to save the matplotlib figure也有可能保存 matplotlib 图

import plotnine as pn

fig, plot = (pn.ggplot()
 + ...

 + pn.theme(panel_background=pn.element_blank())
 + pn.theme(axis_title_y=pn.element_blank())
 + pn.theme(axis_ticks_major_y=pn.element_blank())
 + pn.theme(figure_size=(12, 8))
             ).draw(show=False, return_ggplot=True)

fig.savefig('image.png', dpi=300)

which worked ok for me.这对我来说没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AutoEncoder 的编码器输出中的大多数条目为零,同时用于从高分辨率图像中提取特征 - Most of the entries in encoder output of an AutoEncoder is zero while used for feature extraction from high-resolution images 如何使用seaborn生成高分辨率热图? - How to generate high-resolution heatmap using seaborn? 为 Cartopy map 添加高分辨率底部地形 - Add high-resolution bottom topography to Cartopy map 如何使用 xESMF 将高分辨率 GRIB 网格重新采样为更粗略的分辨率? - How do I resample a high-resolution GRIB grid to a coarser resolution using xESMF? 如何使用 Python 获取高分辨率的谷歌地图卫星图像? - How can I fetch high-resolution google map satellite image using Python? 用Python构造高分辨率图像 - Constructing high resolution images in Python 使用 Opencv 打开高分辨率图像 - Open high resolution images with Opencv 如何在Python中将整数转换为高分辨率时间? 还是如何防止Python掉零? - How do I convert integers into high-resolution times in Python? Or how do I keep Python from dropping zeros? 将大量图像保存为数组 - Saving a high number of images as an array 使用 Python 从 PDF 中提取高分辨率图像 - Extract images from PDF in high resolution with Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM