HORIZONTAL BAR PLOT WITH GAPS

15 次查看(过去 30 天)
Lucas campos
Lucas campos 2020-11-3
Hello,
I have a set of data with a timestamp and the state of two machines. When the machine is turned on I have 1. If turned off, I have 0.
I would like to plot using horizontal bars when each machine is working. Also, I would like to plot the total time in minutes inside the bar.
Any ideas on how to do it?
Thanks a lot
Lucas

回答(1 个)

Mario Malic
Mario Malic 2020-11-3
编辑:Mario Malic 2020-11-3
Here is the heatmap solution, but unfortunately it doesn't return the total time in bar.
clc;
clear;
close all;
M1 = [ones(1,6), zeros(1,4), ones(1,7), zeros(1,3)];
M2 = [zeros(1,5), ones(1,6), zeros(1,5), ones(1,4)];
t1 = datetime(2020,10,26,0,0,0);
t2 = datetime(2020,10,26,19,0,0);
t = (t1 + hours(0:19));
h = heatmap(t, {'Machine 1', 'Machine 2'}, [M1; M2]);
There is a helpful link at Stackoverflow, if you'd like to make it using barh. Also, it is possible to overlay the text with the color background and the total number, but you'd have to generalise the calculation and location, width and height to place it. This is totally doable and could be worthy of file exchange submission.

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by