Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
multiple colormaps in one figure, exported using export_fig

Subject: multiple colormaps in one figure, exported using export_fig

From: Paul

Date: 29 Sep, 2010 11:16:08

Message: 1 of 13

I'm trying to generate an image (single axes ~subplot(1,1,1)) which uses two different colormaps, and includes two colorbars which use both of these too..

I've generated the plots, one at a time using freezeColors (http://www.mathworks.com/matlabcentral/fileexchange/7943) between plotting the two components (using separate colormaps) to preserve the colormap of both the plotted component and its corresponding colorbar.

I'm then trying to export this to a vector *.eps file using export_fig.

The problem that I'm having is export_fig uses the painters renderer to export vector graphics, whereas freezeColors explicitly doesn't support the painters renderer as this renderer doesn't support rgb color data (http://atonal.ucdavis.edu/resources/docs/matlab/public/utils/freezeColors.html)

Does anyone have any suggestions to find a work around here?

Subject: multiple colormaps in one figure, exported using export_fig

From: Oliver Woodford

Date: 29 Sep, 2010 11:59:08

Message: 2 of 13

"Paul " wrote:
> I'm trying to generate an image (single axes ~subplot(1,1,1)) which uses two different colormaps, and includes two colorbars which use both of these too..

This, and the fact that you want to export to vector graphics, is in essence is the problem here. It has nothing to do with export_fig. Using:
   print -depsc2 -painters test.eps
will have the same problem, as will the on screen figure when you use:
   set(gcf, 'Renderer', 'painters')
You will also see the warining:
   Warning: RGB CData not yet supported in Painter's mode
which explains the problem. What freezeColors does (a guess here, but it's what I'd do) is to convert the first image from indexed colour to RGB colour. The trouble is that the painters renderer supports the first but not the second type of image.

You somehow need to keep both sets of data as indexed colour, which means you actually need to have two separate colormaps when a MATLAB figure can only have one! This is a real pain, and I really hope that some future (but not too distant) version of MATLAB supports more than one colormap per figure. But in the meantime I suggest you use the non-trivial workaround suggested here:
http://www.mathworks.com/help/techdoc/creating_plots/bqsxy8a-1.html#brdjjbz-1

Good luck with it. You'll need it!

And if you give up, I suggest you use:
    export_fig -r300 test.tif
as an alternative, and simply convert test.tif to an eps in an external package, like Inkscape. The output will be rasterized, but the quality will be reasonable.

HTH,
Oliver

Subject: multiple colormaps in one figure, exported using export_fig

From: Oliver Woodford

Date: 29 Sep, 2010 13:10:29

Message: 3 of 13

"Oliver Woodford" wrote:
> What freezeColors does (a guess here, but it's what I'd do) is to convert the first image from indexed colour to RGB colour. The trouble is that the painters renderer supports the first but not the second type of image.

Actually, I've found that the painters renderer can output truecolor images fine, so I have no idea why it isn't working in this case. Perhaps freezeColors does something different.

Oliver

Subject: multiple colormaps in one figure, exported using export_fig

From: Oliver Woodford

Date: 29 Sep, 2010 13:30:27

Message: 4 of 13

"Oliver Woodford" wrote:
> > What freezeColors does (a guess here, but it's what I'd do) is to convert the first image from indexed colour to RGB colour. The trouble is that the painters renderer supports the first but not the second type of image.
>
> Actually, I've found that the painters renderer can output truecolor images fine, so I have no idea why it isn't working in this case. Perhaps freezeColors does something different.

Paul

freezeColors seems to work fine on images, but I guess doesn't work with patch structures. Try changing your call to pcolor (others: Paul emailed me his code) to imagesc. The good news is that you should be able to get the figure as you want it.

Regards,
Oliver

Subject: multiple colormaps in one figure, exported using export_fig

From: Paul

Date: 30 Sep, 2010 06:01:24

Message: 5 of 13

"Oliver Woodford" <o.j.woodford.98@cantab.net> wrote in message <i7vf1j$3e$1@fred.mathworks.com>...
> "Oliver Woodford" wrote:
>
> freezeColors seems to work fine on images, but I guess doesn't work with patch structures. Try changing your call to pcolor (others: Paul emailed me his code) to imagesc. The good news is that you should be able to get the figure as you want it.
>
> Regards,
> Oliver

Thanks for this Oliver.. Yep, using imagesc (along with set(gca,'YDir','normal');) solved my problem with the vector (*.eps) export.. I just need to fiddle my colormaps to rid the NaN=black fill that comes along with imagesc..

Subject: multiple colormaps in one figure, exported using export_fig

From: Oliver Woodford

Date: 30 Sep, 2010 09:14:06

Message: 6 of 13

"Paul " wrote:
> "Oliver Woodford" wrote:
> >
> > freezeColors seems to work fine on images, but I guess doesn't work with patch structures. Try changing your call to pcolor (others: Paul emailed me his code) to imagesc. The good news is that you should be able to get the figure as you want it.
> >
> > Regards,
> > Oliver
>
> Thanks for this Oliver.. Yep, using imagesc (along with set(gca,'YDir','normal');) solved my problem with the vector (*.eps) export.. I just need to fiddle my colormaps to rid the NaN=black fill that comes along with imagesc..

An easy way to do this, which will also reduce the colour discretization in your background image, is to download this package:
   http://www.mathworks.com/matlabcentral/fileexchange/16233
and replace your call to imagesc with:
   imsc(x, y, data, cmap, 'w');
where cmap is the colormap you're using for that data. The 'w' means set all NaNs to white.

Oliver

Subject: multiple colormaps in one figure, exported using export_fig

From: Paul

Date: 9 Oct, 2010 03:27:03

Message: 7 of 13

"Oliver Woodford" <o.j.woodford.98@cantab.net> wrote in message <i81kcu$bi9$1@fred.mathworks.com>...
> An easy way to do this, which will also reduce the colour discretization in your background image, is to download this package:
> http://www.mathworks.com/matlabcentral/fileexchange/16233
> and replace your call to imagesc with:
> imsc(x, y, data, cmap, 'w');
> where cmap is the colormap you're using for that data. The 'w' means set all NaNs to white.
>
> Oliver

Thanks for the tip Oliver.. I downloaded that code package and appear to have hit some problems.. I keep getting the error:

h = imsc(x,y,data,cmap,'w'); % Try imsc from Oliver Woodford
??? Error using ==> sc>parse_inputs at 555
Mask is not a logical array
Error in ==> sc at 167
[map limits mask] = parse_inputs(I, varargin, y, x);
Error in ==> imsc at 34
    [I clim map] = sc(varargin{:});

Any tips for a imsc noob here?

Subject: multiple colormaps in one figure, exported using export_fig

From: Oliver Woodford

Date: 9 Oct, 2010 08:20:06

Message: 8 of 13

"Paul " wrote:
> "Oliver Woodford" wrote:
> > An easy way to do this, which will also reduce the colour discretization in your background image, is to download this package:
> > http://www.mathworks.com/matlabcentral/fileexchange/16233
> > and replace your call to imagesc with:
> > imsc(x, y, data, cmap, 'w');
> > where cmap is the colormap you're using for that data. The 'w' means set all NaNs to white.
> >
> > Oliver
>
> Thanks for the tip Oliver.. I downloaded that code package and appear to have hit some problems.. I keep getting the error:
>
> h = imsc(x,y,data,cmap,'w'); % Try imsc from Oliver Woodford
> ??? Error using ==> sc>parse_inputs at 555
> Mask is not a logical array
> Error in ==> sc at 167
> [map limits mask] = parse_inputs(I, varargin, y, x);
> Error in ==> imsc at 34
> [I clim map] = sc(varargin{:});
>
> Any tips for a imsc noob here?

Hi Paul

I would first make sure you are using the correct input arguments. Specifically, make sure that x and y are correct. See
   help imsc
for a description of their form.

If they are correct and you still get the problem, let me know.
Oliver

Subject: multiple colormaps in one figure, exported using export_fig

From: Paul

Date: 11 Oct, 2010 05:41:03

Message: 9 of 13

"Oliver Woodford" <o.j.woodford.98@cantab.net> wrote in message <i8p8jm$732$1@fred.mathworks.com>...
> Hi Paul
>
> I would first make sure you are using the correct input arguments. Specifically, make sure that x and y are correct. See
> help imsc
> for a description of their form.
>
> If they are correct and you still get the problem, let me know.
> Oliver

Ok great, I have successfully used imsc to plot up using the correct colourmap, however it would appear that attempting to control the colour axis of this created image is problematic.. How do I constrain the colour range, so using caxis or Clims? Can I do this?

Currently my output image appears to plot into a much broader colour range (colour intensities appear to be much less) than in previously generated plots where I was able to explicitly set the caxis/Clims

Subject: multiple colormaps in one figure, exported using export_fig

From: Oliver Woodford

Date: 11 Oct, 2010 08:24:04

Message: 10 of 13

"Paul " wrote:
> Ok great, I have successfully used imsc to plot up using the correct colourmap, however it would appear that attempting to control the colour axis of this created image is problematic.. How do I constrain the colour range, so using caxis or Clims? Can I do this?
>
> Currently my output image appears to plot into a much broader colour range (colour intensities appear to be much less) than in previously generated plots where I was able to explicitly set the caxis/Clims

You can set the intensity range in the call to imsc:
imsc(x, y, image_data, clims, cmap, 'w');

Regards,
Oliver

Subject: multiple colormaps in one figure, exported using export_fig

From: Paul

Date: 11 Oct, 2010 08:39:04

Message: 11 of 13

"Oliver Woodford" <o.j.woodford.98@cantab.net> wrote in message <i8uhj4$1ii$1@fred.mathworks.com>...
> You can set the intensity range in the call to imsc:
> imsc(x, y, image_data, clims, cmap, 'w');
>
> Regards,
> Oliver

Excellent Oliver.. Perfect!
I hunted through the "sc" help, however didn't link "limits" with caxis/Clim.. Sorry..

Subject: multiple colormaps in one figure, exported using export_fig

From: Camille Couzi

Date: 2 Nov, 2010 16:10:04

Message: 12 of 13

Hi Oliver,
I wrote you one month ago about your sc function. I am using it to display imagesc matrix wich contains NaN values. I want NaN values to be displayed in black, and that the black color don't appear on the colorbar.
I am writing:
sc(matrix, 'jet', 'k');
set(eje, 'DataAspectRatioMode', 'auto')

and when I click on the matrix to display (I am working on a GUI with many matrix), I get this error (very long, sorry, but I paste it in total so that you could perhaps say me what the problem is)




??? Error using ==> getappdata
Invalid object handle

Error in ==> scribe.colorbar.init>localResetColorBarProperties at 189
cbar.methods('setOrientation',ax,loc);

Warning: Error occurred while evaluating listener callback.
> In colormap at 95
  In ploteo_postfiltrado at 22
  In Inicio>Ploteo_plot2 at 732
  In hgfeval at 63
  In uitools.uibuttongroup.childAddedCbk>manageButtons at 80
??? Error using ==> getappdata
Invalid object handle

Error in ==> scribe.colorbar.init>localResetColorBarProperties at 189
cbar.methods('setOrientation',ax,loc);

Warning: Error occurred while evaluating listener callback.
> In colormap at 95
  In ploteo_postfiltrado at 22
  In Inicio>Ploteo_plot2 at 732
  In hgfeval at 63
  In uitools.uibuttongroup.childAddedCbk>manageButtons at 80
??? Error using ==> getappdata
Invalid object handle

Error in ==> scribe.colorbar.init>localResetColorBarProperties at 189
cbar.methods('setOrientation',ax,loc);

Warning: Error occurred while evaluating listener callback.
> In imdisp at 165
  In sc at 193
  In ploteo_postfiltrado at 28
  In Inicio>Ploteo_plot2 at 732
  In hgfeval at 63
  In uitools.uibuttongroup.childAddedCbk>manageButtons at 80
??? Error using ==> getappdata
Invalid object handle

Error in ==> scribe.colorbar.init>localResetColorBarProperties at 189
cbar.methods('setOrientation',ax,loc);

Warning: Error occurred while evaluating listener callback.
> In imdisp at 165
  In sc at 193
  In ploteo_postfiltrado at 28
  In Inicio>Ploteo_plot2 at 732
  In hgfeval at 63
  In uitools.uibuttongroup.childAddedCbk>manageButtons at 80
??? Error using ==> getappdata
Invalid object handle

Error in ==> scribe.colorbar.init>localResetColorBarProperties at 189
cbar.methods('setOrientation',ax,loc);

Warning: Error occurred while evaluating listener callback.
> In imdisp>display_image at 428
  In imdisp at 183
  In sc at 193
  In ploteo_postfiltrado at 28
  In Inicio>Ploteo_plot2 at 732
  In hgfeval at 63
  In uitools.uibuttongroup.childAddedCbk>manageButtons at 80
??? Error using ==> getappdata
Invalid object handle

Error in ==> scribe.colorbar.init>localResetColorBarProperties at 189
cbar.methods('setOrientation',ax,loc);

Warning: Error occurred while evaluating listener callback.
> In imdisp>display_image at 428
  In imdisp at 183
  In sc at 193
  In ploteo_postfiltrado at 28
  In Inicio>Ploteo_plot2 at 732
  In hgfeval at 63
  In uitools.uibuttongroup.childAddedCbk>manageButtons at 80
??? Error using ==> getappdata
Invalid object handle

Error in ==> scribe.colorbar.init>localResetColorBarProperties at 189
cbar.methods('setOrientation',ax,loc);

Warning: Error occurred while evaluating listener callback.
> In sc at 196
  In ploteo_postfiltrado at 28
  In Inicio>Ploteo_plot2 at 732
  In hgfeval at 63
  In uitools.uibuttongroup.childAddedCbk>manageButtons at 80
??? Error using ==> getappdata
Invalid object handle

Error in ==> scribe.colorbar.init>localResetColorBarProperties at 189
cbar.methods('setOrientation',ax,loc);

Warning: Error occurred while evaluating listener callback.
> In sc at 196
  In ploteo_postfiltrado at 28
  In Inicio>Ploteo_plot2 at 732
  In hgfeval at 63
  In uitools.uibuttongroup.childAddedCbk>manageButtons at 80
??? Error using ==> getappdata
Invalid object handle

Error in ==> scribe.colorbar.init>localResetColorBarProperties at 189
cbar.methods('setOrientation',ax,loc);

Warning: Error occurred while evaluating listener callback.
> In sc at 197
  In ploteo_postfiltrado at 28
  In Inicio>Ploteo_plot2 at 732
  In hgfeval at 63
  In uitools.uibuttongroup.childAddedCbk>manageButtons at 80






Thanks in advance for your help.
Camille.

Subject: multiple colormaps in one figure, exported using export_fig

From: Oliver Woodford

Date: 3 Nov, 2010 09:39:04

Message: 13 of 13

"Camille Couzi" wrote:
> Hi Oliver,
> I wrote you one month ago about your sc function. I am using it to display imagesc matrix wich contains NaN values. I want NaN values to be displayed in black, and that the black color don't appear on the colorbar.
> I am writing:
> sc(matrix, 'jet', 'k');
> set(eje, 'DataAspectRatioMode', 'auto')
>
> and when I click on the matrix to display (I am working on a GUI with many matrix), I get [an] error.

Hello Camille

Where did you write to me? If it was via this newsgroup then I'm not guaranteed to read it!

Make sure that you are using the correct handle, i.e. the image handle, when setting the callback function.

Regards,
Oliver

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us