MATLAB Answers

Multiple color plots / colorbars on a single axes

20 views (last 30 days)
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:
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
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?


Sign in to comment.

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 18 Oct 2019
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.

  1 Comment

De Spiegeleer Alexandre
De Spiegeleer Alexandre on 18 Oct 2019
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.

Sign in to comment.

More Answers (0)

Sign in to answer this question.