MATLAB Answers

Misalignment Ticks and Line when changing linewidth

1 view (last 30 days)
Bob photonics
Bob photonics on 23 Mar 2020
Edited: Bob photonics on 26 Mar 2020
So I'm getting a misalignment between a line and my ticks, using version R2016a (and can't update it on the pc that is using it).
I can't find any matlab code that let's me fix this, I looked up the code to control ticks and ticklabels.
my code is below:
Pos_size=[100 100 800 400];
FSax=12;
FWax='bold';
FStitle=16;
FWtitle='bold';
MkSz=20;
Tfig5='Voltage vs FWHM';
Xlab4='Applied potential (V)'; %figs 4 and 5
YlabL1='CPM (M)'; %figs 1 and 2 and 4 and 5
%% plotting figure 5
h5=figure(5);
title(Tfig5,'FontSize',FStitle,'FontWeight',FWtitle)
xlabel(Xlab4,'FontSize',FSax,'FontWeight',FWax)
ylabel(YlabL1,'FontSize',FSax,'FontWeight',FWax)
set(h5,'Position',Pos_size);
hold on
ylim([0 400]);
hax5(1)=plot(Voltage,FWHMVolt,'.-','Linewidth',2,'MarkerSize',MkSz);
ax5=h5.CurrentAxes;
set(ax5,'FontSize',FSax,'FontWeight',FWax,'LineWidth',1);
line([0 0], get(ax5, 'ylim'),'color',[0.7 0.7 0.7],'linestyle','--','Linewidth',1.5); % this is my line (in my actual script I use vline but that's a file from mathworks but does the exact same) -> vline(0,'color',[0.7 0.7 0.7],'linestyle','--','Linewidth',1.5);
box on
% data if someone wants to run the code themselves
Voltage =
-0.1000
0
0.0100
0.0300
0.0500
0.0700
0.1000
0.3000
0.5000
0.7000
0.9000
FWHMVolt =
50
146
145
143
141
141
145
244
304
334
351

  3 Comments

Bob photonics
Bob photonics on 23 Mar 2020
PS I also tried
plot([0 0],get(ax5, 'ylim'),'Linewidth',1.5)
Same issue as before
darova
darova on 23 Mar 2020
What will happen if you change linewidth?
Bob photonics
Bob photonics on 23 Mar 2020
While chnaging the linewidth for the line (or plot) will leave the same issue, it just becomes less obvious when you make it thicker.
Increase the linewidth of the axes (ticks) increase the problem ever so sligthy (need to go to 4 or more for it to be obvious). Which is exactly what I expected to be honest because it was the what I changed (I increased it from the normal size to 1).
Nonetheless I need this higher value as otherwise the ticks/axes are not clear/obvious enough in my opinion.
See linewidth 6 in the image I attached:

Sign in to comment.

Answers (1)

Harsha Priya Daggubati
Harsha Priya Daggubati on 26 Mar 2020
Hi,
I could not reproduce the same in MATLAB R2019b. If it is not okay for you to update to recent versions, then you could try moving your line to align with the ticks as a workaround.

  1 Comment

Bob photonics
Bob photonics on 26 Mar 2020
Thanks for the suggestion it works but will be a hassle.
This will definitely work as long as I don't want to change the linewidths anymore but I'm afraid it will change again if I change the linewidths.
If anyone has a better suggestion or a solution that will work permanently I would still love to hear it.
Anyway I also tested it in 2018a and had the same issue. At work we are still using 2016a on servers ona lab PCs, while on our personal computers we have 2018a. We don't have much control over updates as that's controlled by ICT.
Ps to some this might not look like a big deal, but if you're using a projector, that projects on an entire wall over 3meters wide or you print out A0 posters then this magnified and a lot more obvious.

Sign in to comment.

Sign in to answer this question.

Products


Release

R2016a