How Do I Properly Format my Bar Graph?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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:![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/869745/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/869745/image.png)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/869750/image.png)
Any assistance in helping me format my x-axis is greatly appreciated!
0 Kommentare
Antworten (2)
VBBV
am 22 Jan. 2022
Bearbeitet: VBBV
am 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 Kommentar
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!