Skip to content

Colorbar consist of many segments in SVG output #4480

Closed

Description

@vascotenner

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.

Activity

  1. OceanWolf commented on May 27, 2015

    @OceanWolf
    Member

    I also notice this when saving to pdf, the colorbar looks choppy.

  2. efiring commented on May 27, 2015

    @efiring
    Member

    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.

  3. added a commit that references this issue on May 27, 2015
    dbd157d
  4. self-assigned this
    on May 27, 2015
  5. OceanWolf commented on May 28, 2015

    @OceanWolf
    Member

    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).

  6. efiring commented on May 28, 2015

    @efiring
    Member

    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.

  7. OceanWolf commented on May 28, 2015

    @OceanWolf
    Member

    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...
    normal_size
    zoomed

  8. efiring commented on May 28, 2015

    @efiring
    Member

    @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.

  9. added a commit that references this issue on Jun 7, 2015
    241b3fc
  10. added a commit that references this issue on Jun 8, 2015
    854f74a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions