How Do I Properly Format my Bar Graph?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to plot 2 arrays using the bar() function. The plot successfully displays, but I am trying to change the format for readability.
The following is the code I currently have:
% Clean
close all
clear
clc
format short
dataPoints = 1000;
bars = 4;
data = generateData(dataPoints); % Generrate and store data
sortedData = sort(data); % Sort data in ascending order
[xData , yData] = sortedPlotData(sortedData,bars); % Obtain plotting data
figure
bar(xData,yData)
title('Unnamed Project Title')
xlabel('Number in the Thousands (ie 4,000)')
ylabel('Percent')
xtickformat('%.4f')
ytickformat('percentage')
Because I want help in formatting the plot, I'll ommit the functions, but the plot that comes out is:

First note the x data points are [379.5 , 1138.3 , 1897.2 , 2656] and I have no problem with the y-axis. I am trying to format the x-axis so that the ticks are in decimal form (not scientific), and that there is 1 tick per bar. A good example of what I'm trying to explain comes from the documentation center:

Any assistance in helping me format my x-axis is greatly appreciated!
0 commentaires
Réponses (2)
VBBV
le 22 Jan 2022
Modifié(e) : VBBV
le 22 Jan 2022
x = [379.5 , 1138.3 , 1897.2 , 2656]; % your values
y = rand(size(x));
bar(x, y)
xlabel('Number in the Thousands (ie 4,000)')
ylabel('Percent')
xticks(x); % use xticks same in count with your xvalues
xtickformat('%.1e')
You can use xticks to specify the x-values as an array which aligns with bars
1 commentaire
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


