Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 854f74a

Browse files
committed
Merge pull request #4481 from efiring/rasterize_colorbar
Rasterize colorbar when it has many colors; closes #4480
2 parents bf963a4 + 241b3fc commit 854f74a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Dense colorbars are rasterized
2+
``````````````````````````````
3+
Vector file formats (pdf, ps, svg) are efficient for
4+
many types of plot element, but for some they can yield
5+
excessive file size and even rendering artifacts, depending
6+
on the renderer used for screen display. This is a problem
7+
for colorbars that show a large number of shades, as is
8+
most commonly the case. Now, if a colorbar is showing
9+
50 or more colors, it will be rasterized in vector
10+
backends.

lib/matplotlib/colorbar.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ class ColorbarBase(cm.ScalarMappable):
256256
'min': slice(1, None),
257257
'max': slice(0, -1)}
258258

259+
n_rasterize = 50 # rasterize solids if number of colors >= n_rasterize
260+
259261
def __init__(self, ax, cmap=None,
260262
norm=None,
261263
alpha=None,
@@ -517,6 +519,8 @@ def _add_solids(self, X, Y, C):
517519
colors=(mpl.rcParams['axes.edgecolor'],),
518520
linewidths=linewidths)
519521
self.ax.add_collection(self.dividers)
522+
elif len(self._y) >= self.n_rasterize:
523+
self.solids.set_rasterized(True)
520524

521525
def add_lines(self, levels, colors, linewidths, erase=True):
522526
'''

0 commit comments

Comments
 (0)