Colorbar Minor Tickmarks with 2014b

조회 수: 13 (최근 30일)
David
David 2014년 12월 8일
댓글: David 2014년 12월 9일
I used to be able to turn on minor tickmarks on colorbars prior to version 2014b using the command
set(h_cbar, 'YMinorTick', 'on');
Now, however, I get an error when I run this. Looking through the list of properties for the colorbar, I can't find any way to add minor tick marks to a colorbar. I can add unlabeled tick marks, but they have the same length as the major tick marks.
As an example, the following code run in v. 2012a adds minor tick marks to the figure.
h_f = figure;
h_p = plot(9:20,9:20);
h_c = colorbar;
set(h_c,'YMinorTick','on')
When the same code is run in v. 2014b, I get the error:
Error using matlab.graphics.illustration.ColorBar/set
There is no YMinorTick property on the ColorBar class.
Is there any way to create minor tick marks in v. 2014b, or is it completely lost?
  댓글 수: 1
Star Strider
Star Strider 2014년 12월 8일
It’s likely gone but not completely lost. I’m hoping a number of currently inaccessible properties in HG2 (that were available in previous versions) magickally reappear next year.
Search Undocumented MATLAB as well.
Meanwhile, submit a Support Request asking how to enable the minor ticks in R2014b. There might be an undocumented method.

댓글을 달려면 로그인하십시오.

채택된 답변

matt dash
matt dash 2014년 12월 8일
I don't see it hidden anywhere. Incidentally there is a hidden "Axes" property, but it returns the axes the colorbar is linked to, not the colorbar itself.
Potential workaround: create a new axes on top of the colorbar, and set ITS minor ticks. Use axes('color','none') to get a transparent background so you can otherwise see the colorbar behind it.
  댓글 수: 1
David
David 2014년 12월 9일
I submitted a Support Request to MathWorks, and their response was essentially this. To draw another set of axes on top of the colorbar. A sample code would be:
h_f = figure;
h_p = plot(9:20,9:20);
h_c = colorbar;
h_a = axes('position',h_c.Position);
h_a.YLim = h_c.Limits;
h_a.Color = 'none';
h_a.XColor = 'none';
h_a.YTickLabelRotation = 45.0;
h_a.YTickLabel = [];
h_a.YTick = h_c.Ticks;
h_a.TickDir = h_c.TickDirection;
h_a.Box = 'on';
set(h_a,'YMinorTick','on');
I'm not sure why, but YTickLabelRotation seems to need to be non-zero, or the minor tick marks won't show.
This solution also doesn't allow the plot window to be resized, so the extra axes have to be drawn as a last step.
I haven't yet read through Undocumented Matlab's page on customizing axes, but the MathWorks employee I spoke with suggested I look there. I assume I'll just end up with with Yair said, a property that I can change ( h_c.Ruler.MinorTickVisible ), but doing so has no effect on the colorbar.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Yair Altman
Yair Altman 2014년 12월 9일
h_c.Ruler contains properties that support minor-ticks: MinorTick, MinorTicks and MinorTickVisible (='off' by default). The problem is that for some reason MathWorks have set the MinorTicks property as read-only so it cannot be changed from its default value of empty, so regardless of whether MinorTickVisible is on/off, no minor ticks are displayed.
Still, the availability of these properties probably mean that there's a good chance that they will be enabled in some future Matlab release. If you ask MathWorks support for this, it could help increase the likelihood of this.

카테고리

Help CenterFile Exchange에서 Colorbar에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by