[Matplotlib-users] emulate transparency in eps From: Francesco Montesano - 2012-06-20 14:39 ```Dear list, it might be that this is not the best place to ask, but I guess that there are enough people with experience with colors. I think plots with nice colors and shaded areas are very nice, but for my publication I have to use eps files, that do not support transparency. The script below produce a figure like the one that I would like to make. If I save it as eps all the shaded areas are not transparent and the plot look ugly and unreadable. A way to emulate transparency that I've applied some time ago was to get the RGB value of the transparent color (with DigitalColor Meter on Mac) and to insert it by hand in fill_between, with a low value for the zorder option. The results was fine, but I don't like too much this approach, as any change in color or alpha value would require to go, get the new color, insert it and redo the figure. Is anyone aware of a way to obtain automatically a RGB color that on screen or printed looks similar to the corresponding RGBA? Thanks in advance, Francesco ********Sample code********* "plot with errors done with fill_between. Emulation of alpha in eps" import itertools as it import matplotlib.pyplot as plt import numpy as np col = it.cycle([ 'm', 'r', 'g', 'b', 'c', 'y', 'k', ]) ls = it.cycle( [ '-', '--', '-.', ':' ][::-1]) #figure fig = plt.figure() ax = fig.add_subplot(111) x= np.linspace(0.5,5,100) for i in range(3): c = col.next() l = ls.next() ax.plot( x, np.sin(x)**i, color=c, ls=l, label='\$sin^{0}(x)\$'.format(i), zorder=10+i ) ax.fill_between( x, np.sin(x)**i + 1./x, np.sin(x)**i - 1./x, color=c, linestyle=l, alpha=0.5, zorder=i+1) ax.legend(frameon=False) plt.savefig("test_alpha.pdf") plt.savefig("test_alpha.eps") plt.show() exit() ********End sample code********* ```
 Re: [Matplotlib-users] emulate transparency in eps From: Eric Firing - 2012-06-20 17:49 ```On 06/20/2012 04:38 AM, Francesco Montesano wrote: > Dear list, > > it might be that this is not the best place to ask, but I guess that > there are enough people with experience with colors. > > I think plots with nice colors and shaded areas are very nice, but for > my publication I have to use eps files, that do not support > transparency. > The script below produce a figure like the one that I would like to > make. If I save it as eps all the shaded areas are not transparent and > the plot look ugly and unreadable. > > A way to emulate transparency that I've applied some time ago was to > get the RGB value of the transparent color (with DigitalColor Meter on > Mac) and to insert it by hand in fill_between, with a low value for > the zorder option. The results was fine, but I don't like too much > this approach, as any change in color or alpha value would require to > go, get the new color, insert it and redo the figure. > > Is anyone aware of a way to obtain automatically a RGB color that on > screen or printed looks similar to the corresponding RGBA? > > Thanks in advance, > Francesco Francesco, Can't you achieve the same result more easily by saving as pdf and then using something like ghostscript to convert the pdf to eps? Eric ```
 Re: [Matplotlib-users] emulate transparency in eps From: Michael Droettboom - 2012-06-20 18:24 ```The postscript output of the Cairo backend supports transparency emulation, though it hasn't been tested in some time. Eric's suggestion (to output PDF and then convert to EPS) is also a reasonable one. Mike On 06/20/2012 10:38 AM, Francesco Montesano wrote: > Dear list, > > it might be that this is not the best place to ask, but I guess that > there are enough people with experience with colors. > > I think plots with nice colors and shaded areas are very nice, but for > my publication I have to use eps files, that do not support > transparency. > The script below produce a figure like the one that I would like to > make. If I save it as eps all the shaded areas are not transparent and > the plot look ugly and unreadable. > > A way to emulate transparency that I've applied some time ago was to > get the RGB value of the transparent color (with DigitalColor Meter on > Mac) and to insert it by hand in fill_between, with a low value for > the zorder option. The results was fine, but I don't like too much > this approach, as any change in color or alpha value would require to > go, get the new color, insert it and redo the figure. > > Is anyone aware of a way to obtain automatically a RGB color that on > screen or printed looks similar to the corresponding RGBA? > > Thanks in advance, > Francesco > > ********Sample code********* > > "plot with errors done with fill_between. Emulation of alpha in eps" > > import itertools as it > import matplotlib.pyplot as plt > import numpy as np > > col = it.cycle([ 'm', 'r', 'g', 'b', 'c', 'y', 'k', ]) > ls = it.cycle( [ '-', '--', '-.', ':' ][::-1]) > > #figure > fig = plt.figure() > ax = fig.add_subplot(111) > > x= np.linspace(0.5,5,100) > for i in range(3): > c = col.next() > l = ls.next() > ax.plot( x, np.sin(x)**i, color=c, ls=l, > label='\$sin^{0}(x)\$'.format(i), zorder=10+i ) > ax.fill_between( x, np.sin(x)**i + 1./x, np.sin(x)**i - 1./x, > color=c, linestyle=l, alpha=0.5, zorder=i+1) > > ax.legend(frameon=False) > > plt.savefig("test_alpha.pdf") > plt.savefig("test_alpha.eps") > plt.show() > > exit() > ********End sample code********* > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users ```
 Re: [Matplotlib-users] emulate transparency in eps From: Francesco Montesano - 2012-07-16 10:10 ```2012/6/20 Michael Droettboom : > The postscript output of the Cairo backend supports transparency > emulation, though it hasn't been tested in some time. Eric's suggestion > (to output PDF and then convert to EPS) is also a reasonable one. > > Mike > > On 06/20/2012 10:38 AM, Francesco Montesano wrote: >> Dear list, >> >> it might be that this is not the best place to ask, but I guess that >> there are enough people with experience with colors. >> >> I think plots with nice colors and shaded areas are very nice, but for >> my publication I have to use eps files, that do not support >> transparency. >> The script below produce a figure like the one that I would like to >> make. If I save it as eps all the shaded areas are not transparent and >> the plot look ugly and unreadable. >> >> A way to emulate transparency that I've applied some time ago was to >> get the RGB value of the transparent color (with DigitalColor Meter on >> Mac) and to insert it by hand in fill_between, with a low value for >> the zorder option. The results was fine, but I don't like too much >> this approach, as any change in color or alpha value would require to >> go, get the new color, insert it and redo the figure. >> >> Is anyone aware of a way to obtain automatically a RGB color that on >> screen or printed looks similar to the corresponding RGBA? >> >> Thanks in advance, >> Francesco >> >> ********Sample code********* >> >> "plot with errors done with fill_between. Emulation of alpha in eps" >> >> import itertools as it >> import matplotlib.pyplot as plt >> import numpy as np >> >> col = it.cycle([ 'm', 'r', 'g', 'b', 'c', 'y', 'k', ]) >> ls = it.cycle( [ '-', '--', '-.', ':' ][::-1]) >> >> #figure >> fig = plt.figure() >> ax = fig.add_subplot(111) >> >> x= np.linspace(0.5,5,100) >> for i in range(3): >> c = col.next() >> l = ls.next() >> ax.plot( x, np.sin(x)**i, color=c, ls=l, >> label='\$sin^{0}(x)\$'.format(i), zorder=10+i ) >> ax.fill_between( x, np.sin(x)**i + 1./x, np.sin(x)**i - 1./x, >> color=c, linestyle=l, alpha=0.5, zorder=i+1) >> >> ax.legend(frameon=False) >> >> plt.savefig("test_alpha.pdf") >> plt.savefig("test_alpha.eps") >> plt.show() >> >> exit() >> ********End sample code********* >> Hi, I was doing again some search on the topic when I realised that I just replied to Eric. This is my reply (Eric sorry for sending this mail twice to you) I remember trying to convert pdf to eps in different ways with usually ugly results and/or very large files. Now I've tried the following commands on test_alpha.pdf (from http://tex.stackexchange.com/questions/20883/how-to-convert-pdf-to-eps): i) pdf2ps -eps test_alpha.pdf test_alpha.conv.eps ii) gs -q -dNOCACHE -dNOPAUSE -dBATCH -dSAFER -sDEVICE=epswrite -sOutputFile=test_alpha.gs.eps test_alpha.pdf the results are: 39K 2012-06-19 17:37 test_alpha.eps (original eps: no transparency) 23K 2012-06-19 17:37 test_alpha.pdf (original pdf: transparency) 90M 2012-06-20 20:20 test_alpha.gs.eps (converted with gs: transparency) 613K 2012-06-20 20:14 test_alpha.pdf2ps.eps (converted with pdf2ps: transparency [from my understanding it uses gs]) In both the converted cases the texts (tick labels, legend) are badly rendered. The lines and contours of the filled areas look noisier than in the original pdf. It might be that increasing the resolution the situation improves, but the file size increases, which is not an option. Michael, I've tried Cairo (import matplotlib as mpl; mpl.use("Cairo") before importing pyplot), but the eps is not transparent. Cheers, Francesco ```