MATLAB Answers

0

Multiple color plots / colorbars on a single axes

Hi,
I am trying to make a tool to easily visualize outputs from a simulation.
With that in mind, I would like to be able to make slices in the 3D domain for various fields (e.g. velocity, current,...) and still provide flexibility for the user.
Currently, one can call a plot function that will create a figure and make a slice plot at the desired slices for one field:
uni.plot('newfigure','slice','yslice',0,'variable','jz','color','jet','colorposition','left')
where uni is an object of my class, and the various inputs parameters includ one that specifies the variable to plot (here, jz).
Let's call this plot, plot 1.
Now the user can make a second plot, plot 2 on top of the previous one
uni.plot('slice','zslice',0,'variable','ux','color','jet','colorposition','right')
For simplicity, I had decided to create a new axes for each new plot.
However, because the new axes of plot 2 appear on top of the one from plot 1, it does not look like they are plot on the same figure but on top of each other (obviously).
This can be seen in this figure:
To overcome that, I thought, let's just copy the slice from plot 2 into the axes from plot 1 using copyobj and then I can delete the plot that is on top.
This works to some extent but as you can see below, the second slice that was done (that was on top) is now merged in the first axes but its color automatically adapted to the colorbar of plot 1.
My question is then the following:
How to keep the second slice plot "attached" to its own colorbar?
Note that I cannot use the same colorbar because:
1) The variables are separated by several orders of magnitude
2) I would like the user to be able to specify the colormap for each plot they make.
If my approach is wrong, is there any alternative way to treat the problem I presented here?
Best,
Alexandre

  0 Comments

Sign in to comment.

Products


Release

R2018b

1 Answer

Answer by Bjorn Gustavsson on 18 Oct 2019 at 11:18
 Accepted Answer

There are some contributions on the file exchange that deals with this. I thik this is one: colormat-and-colorbar-utilities
You might find some others that suits your task better.
HTH

  1 Comment

Hej björn,
Thanks for the link.
Turns out I found what I needed in there.
I am using the cmapping function to create the RGB of my color data before I copy the slice onto plot 1.
And, after I copied the slice, I set the CData value to the RGB.
I works like a charm, thanks :)
I still wonder why they don't link the colormap to the data rather than to the axes ... but well there is a work around.
Cheers,
Alex.

Sign in to comment.