Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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)

Réponse acceptée

Mathieu NOE
Mathieu NOE le 24 Août 2023
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 commentaires

Connectez-vous pour commenter.

Plus de réponses (1)

Kevin Holly
Kevin Holly le 24 Août 2023
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 commentaires
Alberto Acri
Alberto Acri le 24 Août 2023
Modifié(e) : Alberto Acri le 24 Août 2023
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 le 24 Août 2023
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])

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by