Azzera filtri
Azzera filtri

Discontinuous y axis and dual y axis combined in one plot

15 visualizzazioni (ultimi 30 giorni)
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

Nicholas Scott
Nicholas Scott il 13 Ott 2023
load('Red.mat')
load('Blue.mat')
figure
hold on
t = tiledlayout(2,2,'TileSpacing','compact');
bgAx = axes(t,'XTick',[],'YTick',[],'Box','off');
bgAx.Layout.TileSpan = [2 2];
bgAx.YColor = 'w';
ax2 = axes(t);
ax2.Layout.Tile = 1;
x = ones(1, length(Blue));
plot(ax2,x,Blue, 'bx', 'MarkerSize', 3, 'LineWidth', 0.5)
yline(ax2,22,'--');
ax2.XAxis.Visible = 'off';
ax2.Box = 'off';
ax2.YAxis.Color = 'b';
ylim(ax2,[22 30])
ax3= axes(t);
ax3.Layout.Tile = 2;
ax3.Layout.TileSpan = [2 1];
yyaxis left
yticks([])
ax3.YAxis(1).Color = 'w';
yyaxis right
ax3.YAxis(2).Color = 'r';
hold on
x = 5 * ones(1, length(Red));
plot(x, Red, 'r+', 'MarkerSize', 3, 'LineWidth', 0.5);
plot(x, median(Red), 'rhexagram', 'MarkerSize', 20, 'LineWidth', 2)
ylabel('Total Fluorescence Intensity Change', 'Color', 'r')
xlim([4.9, 5.1]);
ax3.XTick = [5];
ax3.XTickLabels = {'FI Delta'};
ax1 = axes(t);
ax1.Layout.Tile = 3;
hold on
x = ones(1, length(Blue));
plot(ax1,x, Blue, 'bx', 'MarkerSize', 3, 'LineWidth', 0.5)
ax1.YAxis.Color = 'b';
plot(x, median(Blue), 'bhexagram', 'MarkerSize', 20, 'LineWidth', 2)
yline(ax1,0.5,'--');
ax1.Box = 'off';
ylim(ax1,[0 0.5])
% Link the axes
linkaxes([ax1 ax2], 'x')
ylabel(t,'Tau', 'Color', 'b') %Does not lie within the middle of the two despite axis linked
xlim([0.9, 1.1]);
ax = gca;
ax.XTick = [1];
ax.XTickLabels = {'Tau'};
xlabel(t, 'PC3 Alexa Stats')
hold off
fontsize(gcf, 16, "points")
drawnow
exportgraphics(gcf, 'AlexaPC3SpreadTau_FIDelta.png', 'Resolution', 600)

Più risposte (1)

Mathieu NOE
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
  8 Commenti
Nicholas Scott
Nicholas Scott il 13 Ott 2023
Thank you! I tried a few of them, wasn't a fan of how export_fig saved things, and instead of spending too much time trying to recreate the figure with the 200 options, I decided to just change the diamond function. I will repost on here to show the finished and accepted answer.
I appreciate all your help, it would've taken me quite some time without your help!! @Mathieu NOE

Accedi per commentare.

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by