Put block behind colorbar
Show older comments
I have several contour plots on a cylinder that I made in MatLab. In some of them the black text from the colorbar is obstructed by dark colors in the plot. In others, the color of the text is fine so I would rather not change the color of the text. Is there an easy way in MatLab to put a rectangular patch (either white or gray) neatly around the colorbar and the surrounding text but behind it so that only a small amount of the contour is hidden?
I've given a link to 4 .fig files on google drive (they're too big to attach), and a .png of one of them where I put a white block around the colorbar (I would like it to be filled and behind the colorbar but in front of the contour) to show what I am hoping to get.
6 Comments
Adam Danz
on 15 Oct 2019
Why not just set the colorbar location or position so that it's adjacent to the axis?
That would be a lot simpler than what you're requesting.
The problem is twofold. The colorbar is itself an axis and its position is relative to the figure, not relative to the data in your main axes. So you'd have to set a rectangle on your axes in your data-units and then you'd have to position the colorbar axes on top of that rectangle by converting its units to your data units. Of course that's posible but it requires a bunch of other modifications such as setting the axis limits on your main axis and considering figure-resizing. There are other white background objects that also use the same figure coordinates as the colorbar such as adding an additional axis or using an annotation text box. But the 2nd problem is that the colorbar cannot be placed over an annotation box nor upon another axes. So the solution isn't clearcut.
Nathaniel H Werner
on 15 Oct 2019
Edited: Nathaniel H Werner
on 15 Oct 2019
Adam Danz
on 15 Oct 2019
The zip file is crazy large (and as with all downloaded zips, poses a security risk although that typically isn't a problem in this forum). A simple screenshot would be much easier to view and can be hosted here in the forum.
The view angle doesn't affect the colorbar position within the figure so I'm puzzled.
Nathaniel H Werner
on 15 Oct 2019
Edited: Nathaniel H Werner
on 15 Oct 2019
Adam Danz
on 16 Oct 2019
I see what you mean now (I saw your figs).
I think your best bet is to add another axis that's slightly bigger than your colorbar (you can get the size and position of the colorbar from its handle). The axis can be set to be on the edge of your figure. But you can't place the colorbar of one axis on another axis so your "fake" axis will have to have the same colormap and color-range as your original data. Then you assign the colorbar to your new, fake axis. Does that make sense?
Nathaniel H Werner
on 16 Oct 2019
Accepted Answer
More Answers (0)
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

