Highlighten specific x-axis values
41 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aladin Djuhera
am 30 Dez. 2019
Bearbeitet: Adam Danz
am 30 Dez. 2019
Hey guys !
I need some help to plot a small figure for my thesis. I think the question is quite simple but however I have not found a solution yet...
What I want to do is to plot my figure with its x-axis that ranges from 0 to 5 in steps of 0.5. Now I want to add 2 specific values (say 1.1 and 3.387) to the x-axis and label them as f_1 and f_2. I tried using xtick but it did not work. Here's my code:
% Values
x_max = 0.22;
v_max = 1.6;
a_max = 35;
f_1 = v_max/(x_max*2*pi);
f_2 = a_max/(v_max*2*pi);
a_1 = x_max * (2*pi*f_1)^2;
a_2 = a_max;
% Curves
f_c1 = [0 f_1];
y_c1 = [0 a_1];
f_c2 = [f_1 f_2];
y_c2 = [a_1 a_2];
f_c3 = [f_2 5];
y_c3 = [a_max a_max];
% Plot
figure
hold on
grid on
box on
xlabel('Frequency [Hz]')
ylabel('Acceleration [m/s^2]')
title('Dynamic Operating Space')
set(gca,'xtick', [f_1 f_2], 'xticklabel', {'f_1'; 'f_2'})
% Characteristic Frequencies
plot([f_1 f_1], [0 40], '--', 'color', 'red')
plot([f_2 f_2], [0 40], '--', 'color', 'red')
% Dynamic Curves
plot(f_c1, y_c1, 'LineWidth', 2, 'color', 'black')
plot(f_c2, y_c2, 'LineWidth', 2, 'color', 'black')
plot(f_c3, y_c3, 'LineWidth', 2, 'color', 'black')
an_1 = text(0.3, 5.5,'x_{max} = 0.22m');
set(an_1,'Rotation',45)
%set(an_1,'FontSize',12)
% ar_1 = area(f_c1, y_c1);
% set(ar_1, 'FaceColor', [1 0.5 0]);
an_2 = text(2, 22.5,'v_{max} = 1.6m/s');
set(an_2,'Rotation',45)
an_3 = text(4, 36.5,'a_{max} = 35m/s^2');
This is what I got:

If the x-axis would now display the full range in addition to above f_1 and f_2 I'd be very happy.
Any clue ?
Additionally, is there any way to grey out the area under the curves ?
Thank you !
3 Kommentare
Akzeptierte Antwort
Adam Danz
am 30 Dez. 2019
Bearbeitet: Adam Danz
am 30 Dez. 2019
"What I want to do is to plot my figure with its x-axis that ranges from 0 to 5 in steps of 0.5. Now I want to add 2 specific values (say 1.1 and 3.387) to the x-axis and label them as f_1 and f_2."
If you want all ticks 0 : 0.5 : 5 and also the values in f_1 and f_2,
xtickVals = unique([0 : 0.5 : 5, f_1, f_2]);
xtickLabs = compose('%.3g',xtickVals);
xtickLabs(ismembertol(xtickVals,[f_1,f_2])) = {'f_1','f_2'};
set(gca,'xtick', xtickVals, 'xticklabel', xtickLabs, 'xlim', [min(xtickVals),max(xtickVals)])
If you want only the f_1 and f_2 labels,
set(gca,'xtick', [f_1, f_2], 'xticklabel', {'f_1','f_2'}, 'xlim', [0,5])
A better idea might be to use xline() to label those values.
set(gca,'xtick', 0 : 0.5 : 5, 'xlim', [0,5])
xline(f_1,'--r','f_1','LabelVerticalAlignment','bottom')
xline(f_2,'--r','f_2','LabelVerticalAlignment','bottom')
Finally, if you want the underscrore rather than a subscript, set the interpreter to none.
xline(f_1,'--r','f_1','LabelVerticalAlignment','bottom','Interpreter','None')
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
