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

4 次查看(过去 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 CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by