フィルターのクリア

enter values from 0 to N (imposed value) with step of 100 on the x-axis of the bar graph

2 ビュー (過去 30 日間)
Hi. I need to change the values on the x-axis of a bar graph.
I have tried in the following way but it doesn't seem to work. Why? How can I enter values from 0 to 700 (imposed value) with step of 100 on the x-axis of the bar graph?
matrix = [64 440; 65 489; 66 581; 67 563];
figure
hbh = barh(matrix(:,1), matrix(:,2));
N = 700;
step = 100;
vector_x_axis = 0:step:N;
xticks(vector_x_axis)

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 8 月 24 日
hello Alberto
welcome back !
i suppose you wanted to do this
matrix = [64 440; 65 489; 66 581; 67 563];
figure
hbh = barh(matrix(:,1), matrix(:,2));
N = 700;
% step = 100;
% vector_x_axis = 0:step:N;
% xticks(vector_x_axis)
xlim([0 N])
  4 件のコメント

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

その他の回答 (1 件)

Kevin Holly
Kevin Holly 2023 年 8 月 24 日
I'm not exactly sure what you want to see. Are one of the 3 graphs below what you want?
matrix = [64, 440; 65, 489; 66, 581; 67, 563];
N = 700;
step = 100;
vector_x_axis = 0:step:N;
figure
hbh = barh(matrix(:, 1), matrix(:, 2));
xlim([0 700])
figure
hbh = barh(matrix(:, 1), matrix(:, 2));
xticks(vector_x_axis)
xticklabels(vector_x_axis(2:end))
figure
hbh = barh(matrix(:, 1), matrix(:, 2));
xticks(vector_x_axis)
step = 700/6;
vector_x_axis = 0:step:N;
xticklabels(vector_x_axis)
  2 件のコメント
Alberto Acri
Alberto Acri 2023 年 8 月 24 日
編集済み: Alberto Acri 2023 年 8 月 24 日
Thank you for your reply @Kevin Holly.
The final graph I want to get is the first one you showed me, BUT I want to impose on the x-axis a range taking into account both the final 'N' value (700) and the 'step' value.
For example using this code that has N=700 and step=50:
matrix = [64, 440; 65, 489; 66, 581; 67, 563];
N = 700;
step = 100;
vector_x_axis = 0:step:N;
figure
hbh = barh(matrix(:, 1), matrix(:, 2));
xticklabels(vector_x_axis)
a graph is created where the x-axis ranges from 0 to 300 (and not up to N=700) and with steps of 50
Whereas by modifying only the last line:
xticks(vector_x_axis)
In both graphs, the x-axis does not arrive at the value of 700.
Kevin Holly
Kevin Holly 2023 年 8 月 24 日
I'm still not quite sure what you want.
matrix = [64, 440; 65, 489; 66, 581; 67, 563];
N = 700;
step = 50;
vector_x_axis = 0:step:N;
figure
hbh = barh(matrix(:, 1), matrix(:, 2));
xticks(vector_x_axis)
figure
hbh = barh(matrix(:, 1), matrix(:, 2));
xticks(vector_x_axis)
xlim([0 700])

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

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by