フィルターのクリア

How to Display Grid Lines with Specific Distance from One Another?

8 ビュー (過去 30 日間)
Rightia Rollmann
Rightia Rollmann 2017 年 2 月 18 日
コメント済み: Walter Roberson 2017 年 2 月 18 日
I want grid lines for a plot but MATLAB automatically define the number of grid lines. Is there any way to manually define the number of grid lines for a plot?

採用された回答

Walter Roberson
Walter Roberson 2017 年 2 月 18 日
MATLAB put grid lines at every XTick or YTick position. You can set the axes XTick and YTick properties to change where the grid lines are to go.
For example:
number_interior_x_gridlines = 7;
ax = gca;
XL = get(ax, 'XLim');
xticks_at = linspace(XL(1), XL, number_interior_x_gridlines + 2);
set(ax, 'XTick', xticks_at);
  2 件のコメント
Rightia Rollmann
Rightia Rollmann 2017 年 2 月 18 日
I get error while running your code.
I want 10 YTicks but only 2 grid lines
Walter Roberson
Walter Roberson 2017 年 2 月 18 日
number_interior_x_gridlines = 7;
ax = gca;
XL = get(ax, 'XLim');
xticks_at = linspace(XL(1), XL(2), number_interior_x_gridlines + 2);
set(ax, 'XTick', xticks_at);
"I want 10 YTicks but only 2 grid lines"
Then you will need to use line() to draw in the marks and text() to draw in the labels for the place you want the y ticks, using the YTicks setting to control the position of the grid lines. Or, alternately, you can have YTicks set where you want to get those drawn in automatically, and instead use line() to draw in the grid lines.
"grid on displays the major grid lines for the current axes. Major grid lines extend from each tick mark."

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by