How to insert dash-line in a matlab figure?
7 次查看(过去 30 天)
显示 更早的评论
How can i add such horizontal dash-line in a matlab figure? ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/817139/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/817139/image.jpeg)
0 个评论
回答(2 个)
Ayush
2024-6-3
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 个评论
Steven Lord
2024-6-3
x = 1:10;
y = x.^2;
ax = axes;
plot(ax, x, y)
ax.YGrid = 'on';
ax.GridLineStyle = '-.';
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Formatting and Annotation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!