Add grid lines but leave x tick labels unchanged
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to be able to change the grid lines on a plot, but leave the tick labels udner matlab control; I have used this, but it also changes the tick labels.
grid minor
%get current tics
xtic=get(gca,'xtick')
%Add my grid lines
set(gca,'xtick',[min(xreal):realPitch:max(xreal)],'XTickLabel','')
%put back original ticks
set(gca,'XTickLabel',xtic');

I want to kept he xlabels under matlab control to stop the overcrowding as above, but I want to be able to zoom in and use the grid lines to look more closely as the two sets of data, hence I need to change just the grid lines
Is this possible? Thanks
2 comentarios
Oscar Miguel Escrig
el 25 de Jul. de 2024
Hope it works:
Try to workaround the issue by creating another axis with the same relevant properties than the original, without background color and in the same position (if daspect or axis square was used repeat for this new axis). Then modify ticklabels and gridding in different axes according to your needs. Don't forget to linkaxes if you use the scope.
Somethig like this:
antax=gca;
newax=axes('Position',antax.Position,'Color','none','XLim',antax.XLim,'YLim',antax.YLim);
% modify ticklabels and gridding in different axes
linkaxes([antax newax],'xy');
Respuestas (1)
Geoff Hayes
el 7 de Mzo. de 2016
Jason - I think that there has to be a one-to-one "mapping" between the ticks and the labels else MATLAB will cycle through the set of labels. See http://www.mathworks.com/matlabcentral/answers/92565-how-do-i-control-axis-tick-labels-limits-and-axes-tick-locations for details. I noticed this behaviour when I extracted the current set of labels
xTickLabels = cellstr(get(gca,'XTickLabel'));
and then created 10 times as many ticks. I think what you will need to do is take the original set of labels and insert empty strings for each of the new ticks that you have created (assuming that the new set of ticks contains the set of original ticks and their labels).
Ver también
Categorías
Más información sobre Axis Labels en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!