Discontinuous y axis and dual y axis combined in one plot
Mostra commenti meno recenti
Hello All!
I am hoping to accomplish a discontinuous axis for one plot to display outliers without making all other points look like they have no spread, and then plot another plot on a second y axis due to it being entirely different ranges. Breakaxis wasn't doing a great job accomplishing this, so I decided to create the code from scratch. Attached are the blue and red variables that are used in the code.
figure
hold on
t = tiledlayout(2,1,'TileSpacing','compact');
bgAx = axes(t,'XTick',[],'YTick',[],'Box','off');
bgAx.Layout.TileSpan = [2 1];
ax2 = axes(t);
ax2.Layout.Tile = 1;
plot(ax2,x,Blue, 'b*')
yline(ax2,20,':');
ax2.XAxis.Visible = 'off';
ax2.Box = 'off';
ylim(ax2,[20 30])
ax1 = axes(t);
ax1.Layout.Tile = 2;
Blue = allPC3tau;
Red = allPC3Range;
x = ones(1, length(Blue));
hold on
plot(ax1,x, Blue, 'b*')
%plot(x, median(Blue), 'k*', 'MarkerSize', 5, 'LineWidth', 3) cannot add,
%as this hides previous data
yline(ax1,0.4,':');
ax1.Box = 'off';
ylim(ax1,[0 0.4])
% Link the axes
linkaxes([ax1 ax2], 'x')
ylabel('Tau') %Does not lie within the middle of the two despite axis linked
This creates a semi-correct categorical scatter plot, but tau is not over the entire plot, just the second most recent plot.
t.Ylabel('Tau') also does not work.
Additionally,
(see first screenshot)
Then when trying to add the second y axis on the right below the previous code, things begin to breakdown:
yyaxis right
x = 1.2 * ones(1, length(Red));
hold on
plot(x, Red, 'r+', 'MarkerSize', 3, 'LineWidth', 1);
plot(x, median(Red), 'k+', 'MarkerSize', 5, 'LineWidth', 3)
% Set up axes.
xlim([0.9, 1.3]);
ylabel('Total Fluorescence Intensity Change')
ax = gca;
ax.XTick = [1, 1.2];
ax.XTickLabels = {'Tau','FI Delta'};
xlabel('PC3 Alexa Stats')
hold off
This causes the 1st tile to shift the outliers to the second column, despite this being a [2 1] tiled layout. I effectively need to find a way to merge the tiles for the yyaxis right, or potentially create a terrible mess of a 4x4 tiled layout, where the yyaxis right spans over 2 of the tiles.
(see second screenshot)
That sounds like an absolute headache, so I turn to the community to see if y'all have much smarter solutions (as you always do) :).
Thanks y'all!
Nick
Risposta accettata
Più risposte (1)
Mathieu NOE
il 11 Ott 2023
a lazy answer - use yyaxis in a y log scale so you still see the outliers group aside from the main data but no fancy axis break needed (again, a very lazy approach !)
figure(1),
yyaxis left
semilogy(1*ones(size(Blue)),Blue,'*b')
yyaxis right
semilogy(2*ones(size(Red)),Red,'*r')
xlim([0 3])

otherwise , some info's that might help you
A blog about the BreakPlot file - http://blogs.mathworks.com/pick/2008/11/21/breaking-a-plot-to-improve-visualization/#3
8 Commenti
Mathieu NOE
il 11 Ott 2023
yet another lazy / low tech approach :
using this Fex submission : https://www.mathworks.com/matlabcentral/fileexchange/30884-controllable-tight-subplot

you can try to use tidelayout , but as I am very lazy today , I leave it up to you !
load('Red.mat')
load('Blue.mat')
figure(1),
is_out = Blue>1;
Blue_outlier = Blue(is_out);
Blue(is_out) = [];
subplot_tight(2,1,1),
plot(1*ones(size(Blue_outlier)),Blue_outlier,'*b')
xlim([0 3])
set(gca,'XTick',[]);
subplot_tight(2,1,2),
colororder({'k','r'})
yyaxis left
plot(1*ones(size(Blue)),Blue,'*b')
yyaxis right
plot(2*ones(size(Red)),Red,'*r')
xlim([0 3])
Nicholas Scott
il 11 Ott 2023
Mathieu NOE
il 12 Ott 2023
sorry, it's me again !
wanted to play with your code and finally got this :

load('Red.mat')
load('Blue.mat')
figure
colororder({'r','b'})
t = tiledlayout(2,1,'TileSpacing','compact');
bgAx = axes(t,'XTick',[],'YTick',[],'Box','off');
bgAx.Layout.TileSpan = [2 1];
ax2 = axes(t);
ax2.Layout.Tile = 1;
x = ones(1, length(Blue));
plot(ax2,x,Blue, 'b*')
yline(ax2,20,'--');
ax2.XAxis.Visible = 'off';
ax2.Box = 'off';
ylim(ax2,[20 30])
ax1 = axes(t);
ax1.Layout.Tile = 2;
% Blue = allPC3tau;
% Red = allPC3Range;
plot(ax1,x, Blue, 'b*')
hold on
plot(x, median(Blue), 'bd', 'MarkerSize', 20, 'LineWidth', 3); % cannot add, as this hides previous data
yline(ax1,0.4,':');
ax1.Box = 'off';
ylim(ax1,[0 0.4])
% Link the axes
linkaxes([ax1 ax2], 'x')
ylabel('Tau') %Does not lie within the middle of the two despite axis linked
yyaxis right
x = 1.2 * ones(1, length(Red));
plot(x, Red, 'r+', 'MarkerSize', 3, 'LineWidth', 1);
plot(x, median(Red), 'rd', 'MarkerSize', 20, 'LineWidth', 3)
% Set up axes.
xlim([0.9, 1.3]);
ylabel('Total Fluorescence Intensity Change')
ax = gca;
ax.XTick = [1, 1.2];
ax.XTickLabels = {'Tau','FI Delta'};
xlabel('PC3 Alexa Stats')
Nicholas Scott
il 12 Ott 2023
Mathieu NOE
il 12 Ott 2023
ok, challenge accepted !
I have other official duties to accomplish so I will patiently wait until end next week !
Nicholas Scott
il 12 Ott 2023
Modificato: Nicholas Scott
il 12 Ott 2023
Mathieu NOE
il 13 Ott 2023
good job !!
regarding figure export , there are some Fex submissions that seems to outperform the regular matlab stuff (like saveas)
look here :
and more on the Fex web page
Nicholas Scott
il 13 Ott 2023
Categorie
Scopri di più su Labels and Annotations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

