YTickLabels repeating themselves?

13 visualizaciones (últimos 30 días)
Christopher Apfelbach
Christopher Apfelbach el 24 de Ag. de 2020
Comentada: Christopher Apfelbach el 27 de Ag. de 2020
Hello, everyone,
I came across this unusual...bug? feature? today as I was designing something in the App Designer.
This portion of the program simply takes three double values and plots them into the three axes shown below. The YLim and YTick/YTickLabel values have been set manually in the axes as [0,100] and [0,20,40,60,80,100] for the far left, [0,10^6] and [0,10^1,10^2,10^3,10^4,10^5,10^6] for the middle, and [0,1000] and [0,200,400,600,800,1000] for the far right. When I plot the values, however, not only do the YTickLabels change, they also bizarrely jump from the upper limit of the YLim range back to the lower limit of the YLim range, as can be seen in the far left and far right axes, where the value jumps from 100 up to zero or 1000 up to zero.
As you can see from the mouseover, the values each read correctly in the axes, and the heights of the bar graphs are proportional to where the values would be located if the YTickLabels were displaying correctly. I've read all the documentation I can and searched Answers for hours trying to find out why this might be happening. Any ideas?
Thanks,
Chris
  1 comentario
Christopher Apfelbach
Christopher Apfelbach el 27 de Ag. de 2020
For those browsing this thread later, the problem was that the plot function was changing the YTick values of the axes objects by itself so that there were 10 ticks in the far left and far right plot, instead of 5. I changed the starting YTick values to 0:10:100 in the far left plot and 0:100:1000 in the far right plot and the problem in those plots resolved itself. The problem with the middle plot was more difficult to hunt down--it was also changing the YTick value on its own, but even when I manually set the YTick value after plotting, the end result was still wildly skewed. I eventually came across the problem here on the forums: I had set the YLim to [0 100000], but 0 is not a valid minimum value for YLim when the axes are logarithmic. After switching YLim to [0.1 100000], the problem resolved right away.

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 25 de Ag. de 2020
Not a bug.
From the table of uiaxes properties in the documentation, specifically the entry for XTickLabel / YTickLabel / ZTickLabel, "Tick labels, specified as a cell array of character vectors, string array, or categorical array. If you do not want tick labels to show, then specify an empty cell array {}. If you do not specify enough labels for all the ticks values, then the labels repeat." The same note appears in the the documentation for axes properties as well so I'll use a plain old axes for this example.
ax = axes;
set(ax, 'YTick', 0:0.25:1)
set(ax, 'YTickLabel', ["1"; "2"])
5 tick locations and 2 tick labels means the first tick gets the first label, the second tick the second label, the third tick the first label again, etc.
  1 comentario
Christopher Apfelbach
Christopher Apfelbach el 25 de Ag. de 2020
Sure, that makes sense, but in the code I've written, my YTick and YTickLabel arrays are exactly the same, which is why I'm so confused by the axes outputs. Here's the code itself:
% Create AxesPercentVoicing
% app.AxesPercentVoicing = uiaxes(app.TabVocalDemandMetrics);
% title(app.AxesPercentVoicing, 'Percent time spent voicing')
% xlabel(app.AxesPercentVoicing, '')
% ylabel(app.AxesPercentVoicing, 'Percent time spent voicing (%)')
% app.AxesPercentVoicing.PlotBoxAspectRatio = [1 2.4551724137931 1];
% app.AxesPercentVoicing.YLim = [0 100];
% app.AxesPercentVoicing.XTick = [];
app.AxesPercentVoicing.YTick = [0 20 40 60 80 100];
app.AxesPercentVoicing.YTickLabel = {'0'; '20'; '40'; '60'; '80'; '100'};
% app.AxesPercentVoicing.YMinorTick = 'on';
% app.AxesPercentVoicing.YGrid = 'on';
% app.AxesPercentVoicing.Position = [30 24 280 610];
% Create AxesTotalCycles
% app.AxesTotalCycles = uiaxes(app.TabVocalDemandMetrics);
% title(app.AxesTotalCycles, 'Total vocal fold cycles')
% xlabel(app.AxesTotalCycles, '')
% ylabel(app.AxesTotalCycles, 'Vocal fold cycles')
% app.AxesTotalCycles.PlotBoxAspectRatio = [1 2.4551724137931 1];
% app.AxesTotalCycles.YLim = [0 1000000];
% app.AxesTotalCycles.ColorOrder = [0.851 0.3255 0.098;0.9294 0.6941 0.1255;0.4941 0.1843 0.5569;0.4667 0.6745 0.1882;0.302 0.7451 0.9333;0.6353 0.0784 0.1843];
% app.AxesTotalCycles.XTick = [];
app.AxesTotalCycles.YTick = [1 10 100 1000 10000 100000 1000000];
app.AxesTotalCycles.YTickLabel = {'10^{0}'; '10^{1}'; '10^{2}'; '10^{3}'; '10^{4}'; '10^{5}'; '10^{6}'};
% app.AxesTotalCycles.YMinorTick = 'on';
% app.AxesTotalCycles.YGrid = 'on';
% app.AxesTotalCycles.YScale = 'log';
% app.AxesTotalCycles.Position = [350 24 280 610];
% Create AxesMeanCycles
% app.AxesMeanCycles = uiaxes(app.TabVocalDemandMetrics);
% title(app.AxesMeanCycles, 'Mean vocal fold cycles per second')
% xlabel(app.AxesMeanCycles, '')
% ylabel(app.AxesMeanCycles, 'Mean vocal fold cycles per second (Hz)')
% app.AxesMeanCycles.PlotBoxAspectRatio = [1 2.53380782918149 1];
% app.AxesMeanCycles.YLim = [0 1000];
% app.AxesMeanCycles.ColorOrder = [0.4667 0.6745 0.1882;0.302 0.7451 0.9333;0.6353 0.0784 0.1843];
% app.AxesMeanCycles.XTick = [];
app.AxesMeanCycles.YTick = [0 200 400 600 800 1000];
app.AxesMeanCycles.YTickLabel = {'0'; '200'; '400'; '600'; '800'; '1000'};
% app.AxesMeanCycles.YMinorTick = 'on';
% app.AxesMeanCycles.YGrid = 'on';
% app.AxesMeanCycles.Position = [670 24 280 610];

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Axis Labels en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by