How Do I Properly Format my Bar Graph?
14 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
VBBV
2022 年 1 月 22 日
編集済み: VBBV
2022 年 1 月 22 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!