You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Colorbar consist of many segments in SVG output #4480
When exporting an errorbar to svg, it consists of many small segments with different colors. This is a very inefficient way to store rastered information, and this generates a huge SVG file, which is slow to parse. Beceause of this, exports to SVG are very unappealing to me, which is a pity, because SVG is an open alternative for PDF/EPS/PS.
Suggestions:
Most colorbars in matplotlib are many generated by linear interpolation between some specified colors. This interpolation can also be done by the SVG renderer.
Another option is to raster the colorbar to PNG and import it in the SVG.
Fixing this bug probably requires some refractory of the SVG ouput machinery, and it will naturally solve the "white lines" issue.
I think the solution is rasterization. It can be done manually: if you have a colorbar object, say cbar, then cbar.solids.set_rasterized(True) will take care of it. We could add a kwarg to the colorbar method to provide easier access to this, or we could use a heuristic: if the colorbar is essentially a gradient, then rasterize. We don't want to rasterize the colorbar when it is used with filled contours, for example; that would make it less accurate and less efficient.
How do we do it at the moment? I would guess svg gradients (http://www.w3.org/TR/SVG/pservers.html) would work with some colorbars, i.e. those linear in rgb space. Unfortunately svg at the moment doesn't allow non-linear gradients nor gradients in other spaces such as hsl, but perhaps some time in the future (fingers crossed).
We are simply using pcolormesh. I really don't think we should jump through special case hoops for svg to make some colorbars yield more compact code; I think this rasterization fix, or some minor variation of it, should be adequate.
Remember also that we are not fundamentally dealing with gradients but with a discrete set of colors, usually 256 for image-like figures, since that is the default size of the colormap lookup-table. Colorbars are also used for much smaller numbers of discrete colors, most notably but not exclusively in the contourf case.
Not just about compact code, but also about making the image scalable, vector like, but yes I agree with catering for special gradients goes OTT, at least for now (I have no knowledge how the other vector backends compare to SVG). That said as qualitative colormaps don't contain gradients and thus perhaps make for a much simpler case (though perhaps we already treat them differently?).
As for my issues with pdf, see below for screenshots, first image normal size and second when zoomed into the pdf. cmap=YlOrRd screenshots taken using GIMP from pdf displayed using Evince Document Viewer. Notice that in the normal version it looks like the cmap 4 sections per 0.25 interval, and when zoomed I see lots of white lines...
@OceanWolf, yes, that is exactly the problem that keeps coming up in various forms. It is renderer-dependent. Try this PR; I think you will find it solves the problem.
Activity
OceanWolf commentedon May 27, 2015
I also notice this when saving to pdf, the colorbar looks choppy.
efiring commentedon May 27, 2015
I think the solution is rasterization. It can be done manually: if you have a colorbar object, say
cbar, thencbar.solids.set_rasterized(True)will take care of it. We could add a kwarg to the colorbar method to provide easier access to this, or we could use a heuristic: if the colorbar is essentially a gradient, then rasterize. We don't want to rasterize the colorbar when it is used with filled contours, for example; that would make it less accurate and less efficient.Rasterize colorbar when it has many colors; closes matplotlib#4480
OceanWolf commentedon May 28, 2015
How do we do it at the moment? I would guess svg gradients (http://www.w3.org/TR/SVG/pservers.html) would work with some colorbars, i.e. those linear in rgb space. Unfortunately svg at the moment doesn't allow non-linear gradients nor gradients in other spaces such as hsl, but perhaps some time in the future (fingers crossed).
efiring commentedon May 28, 2015
We are simply using pcolormesh. I really don't think we should jump through special case hoops for svg to make some colorbars yield more compact code; I think this rasterization fix, or some minor variation of it, should be adequate.
Remember also that we are not fundamentally dealing with gradients but with a discrete set of colors, usually 256 for image-like figures, since that is the default size of the colormap lookup-table. Colorbars are also used for much smaller numbers of discrete colors, most notably but not exclusively in the contourf case.
OceanWolf commentedon May 28, 2015
Not just about compact code, but also about making the image scalable, vector like, but yes I agree with catering for special gradients goes OTT, at least for now (I have no knowledge how the other vector backends compare to SVG). That said as qualitative colormaps don't contain gradients and thus perhaps make for a much simpler case (though perhaps we already treat them differently?).
As for my issues with pdf, see below for screenshots, first image normal size and second when zoomed into the pdf. cmap=


YlOrRdscreenshots taken using GIMP from pdf displayed using Evince Document Viewer. Notice that in the normal version it looks like the cmap 4 sections per 0.25 interval, and when zoomed I see lots of white lines...efiring commentedon May 28, 2015
@OceanWolf, yes, that is exactly the problem that keeps coming up in various forms. It is renderer-dependent. Try this PR; I think you will find it solves the problem.
Rasterize colorbar when it has many colors; closes matplotlib#4480
Merge pull request #4481 from efiring/rasterize_colorbar