Question

I have a figure created in Matlab which uses a discrete colorbar and a custom colormap. Ideally, I would like to save this as a postscript figure (.eps) so I can do some editing in Inkscape. However, when I save it in .eps format, the colorbar appears to be continuous when viewed in Inkscape (amongst other progams). What do I need to do to stop this?

I also tried saving the figure as a PDF which seemed to work (colorbar was discrete in any program I used to view/edit it), but after some editing in Inkscape and re-saving as a PDF (or other format like .eps and .png), the colorbar switched back to continuous again.

Here is the code for my colorbar and what I used to save it:

cmap=[118 18 19;
      118 18 19;
      184 18 21;
      230 38 44;
      255 127 0;
      255 191 0;
      247 217 9;
      255 248 140;
      182 237 240; 
      145 205 237;
      107 174 232;
      61 144 227;
      32 114 214;
      0 66 135;
      0 31 103;
      0 31 103;
      0 31 103;
      0 31 103;
      0 31 103;
      0 31 103];
cmap=cmap/255;
colormap(cmap)
caxis([-20 30]
cb=colorbar('XTick',[-15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15],'Xlim', [-17.5 17.5]);
export_fig fig1 -pdf -eps -r600 -painters

Here is the PDF version of the colorbar (hopefully). I couldn't work out how to post the EPS version.

How do I stop the colorbar from going continuous? I really need to do some editing as I can't get Matlab to do arrows on the end of my colorbar, and I might need to play around with the text too.

Was it helpful?

Solution 2

The only way I managed to find to stop this is to re-colour each section of the colour bar in Inkscape with the discrete colour that was meant to be in that section. In reality, I think this just inserted another rectangle of that colour within that box, but it worked ok. This wouldn't work if my tickmarks didn't completely separate each section of the colourbar though.

Not a pretty solution, but it worked for me!

OTHER TIPS

This is an issue to do with how Inkscape exports bitmaps, discussed here. The solution is to open the offending pdf file (the one output by Inkscape) in a text editor, find the line(s)

/Interpolate true

and replace it/them with

/Interpolate false

You may print in vector format with

print(gcf, '-dpdf', 'fig.pdf');

You can also set the renderer property of the figure to zbuffer for a raster plot.

set(gcf,'Renderer','zbuffer');

Both display and print a discrete colorbar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top