How can I hide the black line on the right side of colorbar

9 Comments

Hi Hongyun,
By setting the 'Box' property of the colorbar to 'off', you can effectively hide the black line on the right side of the colorbar in Matlab. Here is example code snippet.
% Remove the black line on the colorbar
c = colorbar;
c.Box = 'off';
I hope this will help resolve your problem. Please let me know if you have any further questions.
I have tried the solution you provided, but it cannot solve my problem.
How did you create this colorbar? It doesn't look like a colorbar created with the built-in MATLAB colorbar() function.
Hi Hongyun,
Could you share the code snippet that you are having issue with,it will help clarify the problem.
Hello Hongyun,
figure(1)
mesh(peaks(40))
cb = colorbar
cb.Box = 'off'
With cbarrow not involved, you still see a vertical line on the right hand side of the colorbar. That line appears to be associated with the scale and the tick marks, and it may not be so easy to remove.
Yeah, it is not easy to remove the vertical line on the right hand side of the colorbar.
@Umar, if you post your Answers down below in the official Answers section, you can get credit (reputation points) for it if someone accepts it or votes for it. Up here in the comments section, you can't, because up here is where people generally just ask for clarification of the question rather than give an answer. 🙂
@Image Analyst,
Your comments have been noted. By the way how do you get nominated for most anticipated in 2024 by Mathworks, any suggestions.

Sign in to comment.

 Accepted Answer

I tried reproducing the same issue. When I searched for help with this function, unfortunately, I could not find anything. It looks like you are using a function that was developed by a community member. I also tried searching for the source code, but I could not find it. I think that unless we have the source code, we cannot debug this. I hope the above information is helpful.
Thanks

8 Comments

@Hongyun,
Here is an example of how you can use the `cbarrow` function to achieve this:
% Create a color bar with a black line on the right side
colorbar;
cbarrow; % Hide the black line on the right side of the color bar
cbarrow('delete');
Please see attached plots.
Hope this answers your question.
At least for me, that just deletes the arrows and modified box, leaving a colorbar with no box.
colorbar
cbarrow
cbarrow('delete')
The part that we need to get rid of is the axle (the part of the box from which ticks originate). That can be done directly:
figure
hcb = colorbar;
hcb.Box = 'off'; % this needs to be set before calling cbarrow()
cbarrow
hcb.Ruler.Axle.Visible = 'off'; % hide the axle, but not the ticks
The problem is that editing private properties of graphics objects may not always work out. You may find that attempting to save or edit the figure after this point will revert the specific change you made.
% see if we can save a screenshot without it reverting
saveas(gcf,'test.png')
% load the captured image
figure
imshow('test.png')
In this simplified example, it seems to allow me to save the figure with saveas(), but I make no guarantees that editing undocumented properties in this way won't fail in other cases.

@ Hongyun,

Here are my attachments which were lost while being edited regarding cbarrow function.

@DGM,
Thx 😊 for your contribution and helpful comments, really appreciated.
@Umar @DGM Thank you both for helping me solve this problem! You are the best!
@Hongyun, glad to help out. Now,it’s time to accept answer. Also, I would like to thank @SACHIN KHANDELWAL for his contribution and help towards resolving this problem as well.

Sign in to comment.

More Answers (0)

Products

Release

R2024a

Asked:

on 27 Jul 2024

Commented:

on 1 Aug 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!