Change grid Line Width

663 ビュー (過去 30 日間)
Faruk
Faruk 2014 年 10 月 8 日
コメント済み: Adam Danz 2023 年 6 月 20 日
Hi, I used default axes line width as 1.5 in Matlab2014a and my grids were fine. When I increase the axes line width in Matlab2014b, it increases the grid line width and create a very ugly plot specially if I save it as eps or pdf. How can I set axes line width to 1.5 and and grid line width to 0.5 Thank you

採用された回答

Toshia M
Toshia M 2023 年 3 月 17 日
Starting in R2023a, you can change the thickness of grid lines independently of the box outline and tick marks by setting the GridLineWidth property of the axes. For example:
plot([0 3 1 6 4],"LineWidth",2)
grid on
ax = gca;
ax.LineWidth = 2;
ax.GridLineWidth = 1;
You can also set the minor grid line width by setting the MinorGridLineWidth property. For more information on both of these axes properties, see Axes properties.
  2 件のコメント
AK Nahin
AK Nahin 2023 年 6 月 20 日
It is showing this error. I cannot find any solution. Even Example in axis properties also shows the same error.
Unrecognized property 'GridLineWidth' for class 'matlab.graphics.axis.Axes'.
Adam Danz
Adam Danz 2023 年 6 月 20 日
As @Toshia M mentioned, this functionality became available in MATLAB R2023a. Check your MATLAB release using the ver function or look at the upper left corner of the MATLAB desktop.

サインインしてコメントする。

その他の回答 (3 件)

Star Strider
Star Strider 2014 年 10 月 8 日
編集済み: Star Strider 2014 年 10 月 8 日
According to the Axis Properties documentation for R2014b, the axes and grid line widths are all set by the LineWidth property. Setting the GridAlpha or GridColor properties to make them less prominent is probably the best you can do.
EDIT — There may be a way to get around it though if you don’t mind a slightly cumbersome solution.
Assuming this is the effect you want:
x = linspace(0,10*pi,250);
y = sin(0.1*x).*cos(5*x);
plot(x,y, '-r')
grid
hold on
xl = xlim;
yl = ylim;
plot(xl,ones(1,2)*yl(1), '-k', ones(1,2)*xl(1), yl,'-k', 'LineWidth',1.5) % Left & Lower Axes
plot(xl,ones(1,2)*yl(2), '-k', ones(1,2)*xl(2), yl,'-k', 'LineWidth',1.5) % Right & Upper Axes
hold off
produces:
  2 件のコメント
Tiago Dias
Tiago Dias 2018 年 1 月 12 日
How to make it work when i have datetime in the XAxis? it doenst work because my X is datatime
Alutsyah Luthfian
Alutsyah Luthfian 2020 年 9 月 12 日
Thanks man... you are very helpful

サインインしてコメントする。


Md Zillur Rahman
Md Zillur Rahman 2015 年 10 月 15 日
you can solve this issue by using
GridAlpha — Grid-line transparency 0.15 (default) | value in the range [0,1] Grid-line transparency, specified as a value in the range [0,1]. A value of 1 means opaque and a value of 0 means completely transparent.
Setting this property sets the associated mode property to manual.
Example: ax.GridAlpha = 0.5

matt dash
matt dash 2014 年 10 月 8 日
I think Yair Altman just covered this today... there are unlisted "ruler" properties that let you directly control the axes lines: http://undocumentedmatlab.com/blog/customizing-axes-rulers

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by