How to copy paste a bar graph on an existing bar plot and have data merged with bars' width resizing automatically?
2 次查看(过去 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!