Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/users/whats_new/rasterized_colorbar.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Dense colorbars are rasterized
``````````````````````````````
Vector file formats (pdf, ps, svg) are efficient for
many types of plot element, but for some they can yield
excessive file size and even rendering artifacts, depending
on the renderer used for screen display. This is a problem
for colorbars that show a large number of shades, as is
most commonly the case. Now, if a colorbar is showing
50 or more colors, it will be rasterized in vector
backends.
4 changes: 4 additions & 0 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ class ColorbarBase(cm.ScalarMappable):
'min': slice(1, None),
'max': slice(0, -1)}

n_rasterize = 50 # rasterize solids if number of colors >= n_rasterize

def __init__(self, ax, cmap=None,
norm=None,
alpha=None,
Expand Down Expand Up @@ -517,6 +519,8 @@ def _add_solids(self, X, Y, C):
colors=(mpl.rcParams['axes.edgecolor'],),
linewidths=linewidths)
self.ax.add_collection(self.dividers)
elif len(self._y) >= self.n_rasterize:
self.solids.set_rasterized(True)

def add_lines(self, levels, colors, linewidths, erase=True):
'''
Expand Down