How to insert dash-line in a matlab figure?
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
How can i add such horizontal dash-line in a matlab figure?
0 Commenti
Risposte (2)
Ayush
il 3 Giu 2024
Hi,
To add a horizontal dash line in a figure, you can use the "yline" function. This function will help you in drawing horizontal lines at the desired y-values. Refer to an example below for a better understanding:
% Sample data for plotting
x = linspace(0, 2*pi, 100);
y = sin(x);
% Plot the data with a thicker line
plot(x, y, 'LineWidth', 1); % Increase the line width to make it bold
hold on; % Keep the plot active to add more elements
% Add horizontal dash-lines at specified y-values with increased thickness
yValues = -1:0.25:1; % Example y-values where you want dash-lines
for i = 1:length(yValues)
yline(yValues(i), '-.', 'Color', [0 0 0], 'LineWidth', 1.5); % Adds a dashed line at each yValue with increased thickness
end
hold off; % Release the plot
% Customize the plot
xlabel('X-axis');
ylabel('Y-axis');
title('Example Plot');
In the above code, I used a loop to iterate over predefined y-values, at which the horizontal lines should be drawn. You can make changes to these values based on your requirements. The "yline" draws a dashed line ('-.') at each y-value in the specified colour. You can customize the line style and colour as needed.
For more information on the "yline" function, refer to the below documentation:
0 Commenti
Steven Lord
il 3 Giu 2024
x = 1:10;
y = x.^2;
ax = axes;
plot(ax, x, y)
ax.YGrid = 'on';
ax.GridLineStyle = '-.';
0 Commenti
Vedere anche
Categorie
Scopri di più su Graphics Object Properties in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!