How can you prevent axis labels from having uneven spacing from the axis
5 views (last 30 days)
Show older comments
I have some simple test code to plot an array and label the Y-axis:
x = randi(10,40); % random matrix
ax1 = axes;
imagesc(x) % plot matrix as image
labels = {'Some - M','Thing - M', 'A - M', 'ABC - M'}; % some random test labels for Y-axis
set(ax1,'YTickLabel',labels,'YTick',1:2:40,'FontSize',8); % setting up Y-axis ticks and labels
I then save the image using [file>export setup>fonts] and I untick custom size and tick custom name and select Helvetica as the font; I then save it as a vector graphic file (.svg).
The problem: The Y-axis labels having uneven gaps from the Y-axis, as you can see in the image below, they don't line up with the red line.
I think it is something to do with using a non-monospaced font, as when I use a monospaced font such as Courier, the axis labels line up perfectly:
Is there a way to get the labels to line up perfectly when using a non-monospaced font such as Helvetica?
If not, are there any monospaced fonts in MATLAB that look similar to Helvetica?
0 Comments
Answers (1)
Mario Malic
on 1 Oct 2023
Sometimes you have to let things be imperfect. Also, put down that magnifier in the drawer.
Joke aside, try Horizontal Alignment property https://uk.mathworks.com/help/matlab/ref/matlab.graphics.primitive.text-properties.html#budt_bq-1_sep_shared-HorizontalAlignment
5 Comments
Image Analyst
on 1 Oct 2023
Honestly, it's barely noticeable to me, and probably your other viewers, especially when it's shown with a normal size on a normal monitor. Personally I wouldn't worry about it.
See Also
Categories
Find more on Graphics Object Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!