How to copy paste a bar graph on an existing bar plot and have data merged with bars' width resizing automatically?
3 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I have two matlab (2016b) bar plots.
In one graph I have, say, three bars for each x-value, e.g.:
figure;
bar([2 4 6 8 10],[1 2 3 4 5;2 4 9 1 6;3 1 2 7 6].','BarWidth',1)
in the second graph I have another bar graph, at the very same values of x:
figure;
bar([2 4 6 8 10],[7 8 9 8 7].','BarWidth',1)
Now, what I would like to do is to copy-paste the bar from the second plot into the first plot. And this is the easy part I know how to do ;-)
But in addition to this, I'd also like that matlab considers the original bars+the copy-pasted bar as a single group of bars, in such a way that the bars do not overlap, but they are plotted close to each other with automatically resized width (to be controlled through the "BarWidth" property).
Basically, I'd like the final result to be like:
figure;
bar([2 4 6 8 10],[1 2 3 4 5;2 4 9 1 6;3 1 2 7 6;7 8 9 8 7].','BarWidth',1)
I tried to find a programmatic way to do this following the manual copy-paste, but it is unclear to me how matlab "links" the different bar plots in order to automatically resize the bar widths. In fact, each set of bars appears as a separate object, and I cannot understand where matlab stores information regarding which bars matlab has to manage as a "group" when resizing the widths through the "BarWidth" property.
Do you have an idea how to do this, or an hint of the bar object properties that I should look at to achieve the desired behaviour?
Thank you, Gabriele
0 件のコメント
採用された回答
Meeshawn Marathe
2017 年 7 月 28 日
Hi,
Adding the second bar plot data to the existing bar plot using a "hold on" function will overlap with the existing one and currently cannot be grouped in the existing plot.
The best way to append and group the second bar plot would be the command suggested by you:
bar([2 4 6 8 10],[1 2 3 4 5;2 4 9 1 6;3 1 2 7 6;7 8 9 8 7].','BarWidth',1)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Bar Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!