Changing tick labels on x axis
41 ビュー (過去 30 日間)
古いコメントを表示
Hi there,
I'm trying to change the labels on my plot's x-axis, but without any success. I've already read on here through the issues others have had and tried them but it seems I'm doing something wrong.
- When I set my cfg.xlim = ([-0.1 1.5]), it does limit the axis to these but I only get ticks at -0.1, 0.5, 1 and 1.5, which in my case isn't very helpful as I'm looking into milliseconds differences.
- When I try something like cfg.limits = ([-0.1:0.2:1.5]), it cuts my axis at 0.9.
- When I try setting cfg.xticks = ([-0.1:0.2:1.5]), it simply does nothing.
- I tried the below code as well, creating a double of the ticks I'd want.
Could anyone point me to where the problem is please?
Note, the data is EEG data and I'm using singleplotER, which is from the Fieldtrip toolbox. Nevermind, the axis changes should still work, reportedly...
cfg = [];
cfg.showlabels = 'yes';
cfg.fontsize = 15;
cfg.linewidth = 1.5
cfg.layout = 'EEG1010.lay';
cfg.channel = 'CPz';
cfg.ylim = ([-6.5 6.5])
axisticks = ([-0.1:0.2:1.5])
cfg.xmin = ([min(axisticks)])
cfg.xmax = ([max(axisticks)])
cfg.xticks = ([axisticks])
ft_singleplotER(cfg, ER_S_av_RT, ER_NS_av_RT);
axes = gca;
line([0 0],[-6.5 6.5],'Color','Black')
line([0.553 0.553],[-6.5 6.5],'Color','Black')
line([1.149 1.149],[-6.5 6.5],'Color','Black')
line([-1 21],[0 0],'Color','Black')
set(gca,'box','on');
ylabel('Electric Potential (\muV)')
xlabel('Time (s)')
cfg.showlegend = 'yes'
legend({'Condition 1', 'Condition 2'},'Location','southeast','FontSize',12);
title('Difference between conditions')
0 件のコメント
採用された回答
Jan
2022 年 6 月 5 日
This is pure voodoo:
axisticks = ([-0.1:0.2:1.5])
cfg.xmin = ([min(axisticks)])
cfg.xmax = ([max(axisticks)])
cfg.xticks = ([axisticks])
You are defining fields for the control struct cfg which are not used by ft_singleplotER. Read the help section of this function instead of guessing, which arguments are used.
Avoid cargo-cult-porgramming. Parentheses and brackets have a function in Matlab. Do not use them randomly:
axisticks = ([-0.1:0.2:1.5])
cfg.xmin = ([min(axisticks)])
% Leaner and smarter:
axisticks = -0.1:0.2:1.5; % [] is the operator for concatenation
cfg.xmin = -0.1; % Or at least: min(axisticks)
It is completely useless to set a field of cfg after ft_singleplotER ran.
axes = gca;
It is a bad idea to shadown the function called "axes" by a variable. This is not a bug, but it can cause very confusing behavior later.
You did not exactly explain, what you want to achieve. But I guess:
...
ft_singleplotER(cfg, ER_S_av_RT, ER_NS_av_RT);
line([0 0],[-6.5 6.5],'Color','Black')
line([0.553 0.553],[-6.5 6.5],'Color','Black')
line([1.149 1.149],[-6.5 6.5],'Color','Black')
line([-1 21],[0 0],'Color','Black')
set(gca, 'box', 'on', ...
'XTick', -0.1:0.2:1.5);
...
その他の回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!