- drawing the ticks specifically; as you note there isn't sufficient granularity in HG2 to specify individual tick lengths or colors to simulate the effect, or
- deleting the desired ticks then text in the labels for those locations
Is it possible to remove only specific tick mark(s) while keeping tick labels?
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to remove some number of specific tick marks, keeping all others, and keeping all the tick labels.
Is this possible?
As a side note, I know that one can set the TickLength property to [0 0], but that affects all the tick marks.
0 comentarios
Respuesta aceptada
dpb
el 10 de Abr. de 2018
Editada: dpb
el 10 de Abr. de 2018
No; removing a tick clears the associated label; there's an inbuilt 1:1 correlation; "no tickee, no lablee".
To do this would require either
Oh, alternatively, you could probably overlay two axes to achieve the combined effect between the two...
hAx=axes; % new axes
xt=hAx.XTick; % retrieve ticks
hAx.XTick=xt(1:2:end); % clear some
hAx(2)=axes('position',hAx.Position'); % second axes on top of first
hAx(1).XTickLabel=[]; % turn labels of first off
hAx(2).TickLength=[0,0]; % set ticks to zero length 2nd
hAx(2).YTick=[]; % get rid duplicates for y
axes(hAx(1)) % bring first to foreground
results in
Overall, one of the first two options is probably simpler in the end...
5 comentarios
dpb
el 11 de Abr. de 2018
As long as HG2 is structured as is, there is no other "less hacky" procedure; the labels and ticks are intrinsically tied together internally and the tick mark attributes themselves are a global-to-the-axis property rather than by individual tick. All those would have to be turned into arrays with the compounding storage associated with them to be able to do that and the overhead is already heavy.
Más respuestas (1)
Steven Lord
el 10 de Abr. de 2018
You can, but if you've customized the labels it's a bit trickier. Ideally you want to change the XTick and XTickLabel properties simultaneously, to keep them synchronized.
% Sample data
v = 1:10;
C = num2cell('A':'J');
% Plot 1 with the tick labels automatically generated
h = plot(v, v.^2);
ax = ancestor(h, 'axes');
xt = ax.XTick;
labelsToKeep = [1:6 9:10];
ax.XTick = xt(labelsToKeep);
Because the tick labels were automatically generated, the tick labels remain unchanged as we jump from x = 6 to x = 9.
% Plot 2 with the tick labels manually set
figure
h = plot(v, v.^2);
ax = ancestor(h, 'axes');
ax.XTickLabel = C;
xt = ax.XTick;
xtl = ax.XTickLabel;
labelsToKeep = [1:6 9:10];
ax.XTick = xt(labelsToKeep);
In this case, we don't jump directly from F to I. We "jump" from F to G. If your next line set XTickLabel appropriately, you may see a flicker if the display updates between those two lines.
ax.XTickLabel = xtL(labelsToKeep);
If you want to update them both at once, you can use set.
% Plot 3 with the tick labels manually set and changed simultaneously
figure
h = plot(v, v.^2);
ax = ancestor(h, 'axes');
ax.XTickLabel = C;
xt = ax.XTick;
xtL = ax.XTickLabel;
labelsToKeep = [1:6 9:10];
set(ax, 'XTick', xt(labelsToKeep), 'XTickLabel', xtL(labelsToKeep));
In the case of the tick and tick label properties, changing the properties simultaneously isn't quite as important as if you were adding or deleting points by directly modifying the XData and YData properties. If the *Tick and *TickLabel properties are different lengths, MATLAB will compensate (only using the first part of the *TickLabel property or repeating the *TickLabel labels.) It's much more important to change the *Data properties together to avoid a warning.
% Warning
figure
h = plot(v, v.^2);
x = h.XData;
y = h.YData;
labelsToKeep = [1:6 9:10];
h.XData = x(labelsToKeep);
drawnow
h.YData = y(labelsToKeep);
% no warning
figure
h = plot(v, v.^2);
x = h.XData;
y = h.YData;
labelsToKeep = [1:6 9:10];
set(h, 'XData', x(labelsToKeep), 'YData', y(labelsToKeep));
4 comentarios
Steven Lord
el 10 de Abr. de 2018
Ah, I misunderstood the question. Yes, ticks and labels come as a matched set. You could "hack" it by putting a text object in the correct location, but that's not necessarily going to be easy to manage with respect to zooming, panning, and other axis manipulations.
dpb
el 10 de Abr. de 2018
Ayup...those were the discussion points after the Answer posting the possible routes to produce the initial desired appearance...raises the question of just how much more would even be more than theoretically possible to unbundle in HG; to turn the rest of the tick properties into arrays as well as just the present ones so could have the granularity to do such micro-refinements. There's always reason on occasion for yet further customization for a particular plot for a particular, specific purpose; when does the proliferation become totally unmanageable--it's close already what with the introduction of the lower-level ruler behind the axes.
I just wish some the most basic little nits that have been around since the beginning would get fixed; like the inconsistency in default decimal in the formatting -- as shown in the image I attached; those kinds of uglies are trivial but are still around after 30 years. :(
Ver también
Categorías
Más información sobre Grid Lines, Tick Values, and Labels en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!