Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As matplotlib <a href="http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.artist.Artist" rel="nofollow noreferrer">Artists</a> can be rasterized, any class derived from Artist (<a href="http://matplotlib.sourceforge.net/api/artist_api.html" rel="nofollow noreferrer">http://matplotlib.sourceforge.net/api/artist_api.html</a>) can be rasterized with the keyword <code>rasterized</code> set to <code>True</code>. So you can only rasterize your patches.</p> <p>I just tried some combinations and it seems to work. However the quality seems to be not very good (see also <a href="http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg13276.html" rel="nofollow noreferrer">http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg13276.html</a>).</p> <pre><code>import numpy as np import matplotlib.pyplot as plt def add_patch(ax, **kwargs): if 'rasterized' in kwargs and kwargs['rasterized']: ax.set_rasterization_zorder(0) ax.fill_between(np.arange(1, 10), 1, 2, zorder=-1, **kwargs) ax.set_xlim(0, 10) ax.set_ylim(0, 3) if 'alpha' in kwargs and kwargs['alpha'] &lt; 1: txt = 'This patch is transparent!' else: txt = 'This patch is not transparent!' ax.text(5, 1.5, txt, ha='center', va='center', fontsize=25, zorder=-2, rasterized=True) fig, axes = plt.subplots(nrows=4, sharex=True) add_patch(axes[0], alpha=0.2, rasterized=False) add_patch(axes[1], alpha=0.2, rasterized=True) add_patch(axes[2], rasterized=False) add_patch(axes[3], rasterized=True) plt.tight_layout() plt.savefig('rasterized_transparency.eps') </code></pre> <p>I converted the <code>eps</code> to png to show it in the browser:</p> <p><img src="https://i.stack.imgur.com/x6CSD.png" alt="rasterized_transparency.png"></p> <p>See also: <a href="https://stackoverflow.com/questions/5609969/how-to-save-figures-to-pdf-as-raster-images-in-matplotlib">How to save figures to pdf as raster images in matplotlib</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload