保存为.ps / .eps时,Matplotlib图失去透明度 [英] Matplotlib Plots Lose Transparency When Saving as .ps/.eps

查看:932
本文介绍了保存为.ps / .eps时,Matplotlib图失去透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我尝试使用.ps / .eps扩展名保存它们,我在尝试使用透明椭圆体保存一些图时遇到问题。

I'm having an issue with attempting to save some plots with transparent ellipsoids on them if I attempt to save them with .ps/.eps extensions.

这是保存为.png的情节:

Here's the plot saved as a .png:

如果我选择将其保存为.ps / .eps,请执行以下操作:

If I choose to save it as a .ps/.eps here is what it looks like:

我是如何解决这个问题的,是使用ImageMagick转换原始文件png到ps。唯一的问题是png格式的图像大约是90k,转换后它变得不到4M。这不好,因为我有很多这些图像,编辑我的乳胶文件需要太多时间。有人有解决方案吗?

How I got around this, was to use ImageMagick to convert the original png to a ps. The only problem is that the image in png format is about 90k, and it becomes just under 4M after conversion. This is not good since I have a lot of these images, and it will take too much time to compile my latex document. Does anyone have a solution to this?

推荐答案

问题在于 eps 本身不支持透明胶片。

The problem is that eps does not support transparencies natively.

选项很少:


  1. 光栅化图像并嵌入eps文件(如@Molly建议)或导出为pdf并使用一些外部工具(如gs)进行转换(通常也依赖于光栅化)

  1. rasterize the image and embed in a eps file (like @Molly suggests) or exporting to pdf and converting with some external tool (like gs) (which usually relies as well on rasterization)

'模仿'透明度,给定的颜色看起来像给定背景上的透明颜色。

'mimic' transparency, giving a colour that looks like the transparent one on a given background.

我讨论了这个 matplotlib邮件列表,我得到了栅格化的建议,这是不可行的,因为你得到像素化或巨大的数字。当他们放入例如出版物时,它们不能很好地扩展。

I discussed this for sure once on the matplotlib mailing list, and I got the suggestion to rasterize, which is not feasible as you get either pixellized or huge figures. And they don't scale very nicely when put into, e.g., a publication.

我个人使用第二种方法,虽然不理想,但我发现它已经足够好了。我写了一个小的 python脚本,它从此SO帖子获取具有透明度的颜色的纯RGB表示

I personally use the second approach, and although not ideal, I found it good enough. I wrote a small python script that implements the algorithm from this SO post to obtain a solid RGB representation of a colour with a give transparency

编辑

在你的情节的特定情况下,尝试使用 zorder 用于订购零件的关键字。尝试使用 zorder = 10 作为蓝色椭圆, zorder = 11 表示绿色和对于hexbins,zorder = 12

In the specific case of your plot try to use the zorder keyword to order the parts plotted. Try to use zorder=10 for the blue ellipse, zorder=11 for the green and zorder=12 for the hexbins.

这样蓝色应该低于一切,然后是绿色椭圆,最后是六角形。情节也应该是可读的纯色。如果你喜欢png中的蓝色和绿色,你可以尝试使用 mimic_alpha.py

This way the blue should be below everything, then the green ellipse and finally the hexbins. And the plot should be readable also with solid colors. And if you like the shades of blue and green that you have in png, you can try to play with mimic_alpha.py.

编辑2

如果您100%确定 使用eps,那么我想到了几个变通方法(这绝对比你的情节更丑):

If you are 100% sure that you have to use eps, there are a couple of workarounds that come to my mind (and that are definitely uglier than your plot):


  1. 只需在上面绘制椭圆边框hexbins。

  2. 获取每个六边形的中心和幅度,(可能丢弃所有零点)并制作散点图使用与 hexbin 中相同的颜色贴图,并根据需要调整标记大小和形状。您可能想要在其上重绘椭圆边框

  1. Just draw the ellipse borders on top of the hexbins.
  2. Get centre and amplitude of each hexagon, (possibly discard all zero bins) and make a scatter plot using the same colour map as in hexbin and adjusting the marker size and shape as you like. You might want to redraw the ellipses borders on top of that

这篇关于保存为.ps / .eps时,Matplotlib图失去透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆