Plotting a bar graph with a large x-axis

12 ビュー (過去 30 日間)
Brenden Sluyter
Brenden Sluyter 2020 年 3 月 27 日
編集済み: Ajay Pattassery 2020 年 5 月 7 日
I'm trying to plot a bar graph with a very large x-axis. When I do this, it makes my data at the end close to zero look very skinny. Below is what I want it to look like (graph taken from TestLab) and what Im getting in matlab. Is there a way to shrink the x-axis to only the values I need?
Thank you in advance.
  4 件のコメント
Rik
Rik 2020 年 3 月 27 日
You would need to make that yourself because it is probably not something you should be doing. You can either use multiple axes objects or adjust the x values and set the xlabels (so instead of plotting 1 2 10 11 you plot 1 2 3 4 and set the labels to 1 2 10 11).
Mohammad Sami
Mohammad Sami 2020 年 3 月 27 日
If your bar charts are at discrete values, one way is to convert your x-axis into a categorical variable. Then plot against the categorical variable.

サインインしてコメントする。

回答 (1 件)

Ajay Pattassery
Ajay Pattassery 2020 年 5 月 7 日
編集済み: Ajay Pattassery 2020 年 5 月 7 日
Here assume you are plotting the bar plot with x and y as defined below.
x = [1 100 100000];
y = [1 2 4];
bar(x,y)
You will get an output similar to the one you have got above due to the huge scale of the x-axis.
For that, define x as just integers from 1 to number of elements in your x values. Then using xticklabels, define the tick labels.
xModified = 1:length(x)
bar(xModified,y)
xticklabels(gca,{'1','100','100000'});
Alternatively, You can use a logarithemic scale on the x axis and then use xticks and xlabels to label the x axis. This makes bar to be placed at the relative location with respect to the x value.
y = [1 2 4];
x = [1 100 100000];
bar(log(x),y);
xticks(log(x))
xticklabels([{'1'},{'100'},{'1000000'}])

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by