how to edit the axes tick labels?

1 view (last 30 days)
Hi,
in my bachelor thesis I'm trying to figure out how human inflows affect rivers in properties like temperature, conductivity or nitrogen concentration. My data include the year and the point of measurement. I put the time on the y axis (I know that's uncommon but it looks better this way compared to the time being on the x axis) and the 4 points of measurement in the river on the x axis. I visualized the regarded parameter (e.g. temperature) with a colorbar in a scatter plot. I like the result very much because it includes both the temporally and the spatial development. Yet I would like to change two things: first, the numbers of the years are a little too close to the y-axis and they (nearly) touch the colored points, so I would like to move them a bit to the left. And second, it seems matlab wanted to create this plot as a square: is it possible to minimize the gap between the numbers 1, 2, 3 and 4? I'm using MATLAB version 2020a.
Thank you for your help!

Accepted Answer

Star Strider
Star Strider on 7 Jun 2021
Edited: Star Strider on 7 Jun 2021
Some of that can be done by setting the xlim property, the rest by decreasing the width of the axes ysiung the 'Position' property —
figure
scatter(1:4, (1:11).'*ones(1,4), 'filled')
set(gca,'YTick',1:11, 'YTickLabel',2010:2020, 'XTick',1:4, 'XTickLabel',1:4);
xlim([0.9 4])
pos = get(gca,'Position')
pos = 1×4
0.1300 0.1100 0.7750 0.8150
set(gca,'Position',pos+[0 0 -0.3 0])
EDIT — (7 Jun 2021 at 15:50)
The correct approach also depends on how the original data were plotted. Plotting them originally with the years on the y-axis permits using the 'TickLabelFormat' property.
Example —
figure
scatter(1:4, (2010:2020).'*ones(1,4), 'filled')
Ax = gca;
Ax.YAxis.TickLabelFormat = '%d '; % Add Five Spaces To The Right Of The Tick Labels
pos = Ax.Position;
Ax.Position = pos+[0 0 -0.3 0];
.
  2 Comments
Marcel Linde
Marcel Linde on 7 Jun 2021
Thank you, that worked perfectly!!
Star Strider
Star Strider on 7 Jun 2021
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!