Is there a (manual or automatic) way of cutting out several parts of the y-axis for certain x-values in a Matlab plot? I found solutions in other programming languages (see 2 links below), but not for Matlab, except for BreakAxis
and BreakYaxis
on File Exchange, but this only works for one break.
I am also posting my code below, for which I would like to implement it. I would like to have a y-axis break for each yNegData
and yPosData
, i.e. two breaks, each at [0.3*min(yNegData) 0.7*min(yNegData]
and [0.3*max(yPosData) 0.7*max(yPosData]
.
If you could write it in a way that I could use it for different kinds of plots (not only bar, but also line, for example), that would be very useful.
http://lagrange.univ-lyon1.fr/docs/matplotlib/examples/pylab_examples/broken_axis.html
Using gnuplot, how to 'cut out' usused y-axis regions of the graph
The code:
revenue = ones(100,1);
opex = -1*ones(100,1);
opex(10:15,1) = 3;
data{1} = revenue;
data{2} = opex;
colors = parula(numel(data));
labels = {'Revenue','Opex'};
for i = 1:numel(data)
dataNeg{i} = data{i};
dataNeg{i}(data{i}>0) = 0;
dataPos{i} = data{i};
dataPos{i}(data{i}<0) = 0;
mdata(i) = nnz(dataPos{i}); % was: mean(data{i});
end
[~,posOrder] = sort(mdata,'ascend');
[~,negOrder] = sort(mdata,'descend');
yDataPos = [dataPos{posOrder}];
yDataNeg = [dataNeg{negOrder}];
hold on;
bNeg = bar(yDataNeg,'stack');
bPos = bar(yDataPos,'stack');
for i= 1:numel(data)
set(bNeg(i),'FaceColor',colors(negOrder(i),:))
set(bPos(i),'FaceColor',colors(posOrder(i),:))
end
legend(labels{:});
hold off;