How to make inset figure with two y-axes

5 visualizaciones (últimos 30 días)
Irem Altan
Irem Altan el 28 de Jul. de 2022
Comentada: Voss el 29 de Jul. de 2022
I can make a figure with two y-axes, using yyaxis left and yyaxis right. See here, for instance. This results in a plot where the left and right y-axes have different colors, and so do the associated data. Now, I want to use this as an inset in another figure. I try something like this:
% initial plot
plot(d(:,1),d(:,2))
% make the inset
axes('Position',[0.4,0.7,0.2,0.2])
box on
% double y-axes for the inset
yyaxis left
scatter(d2x,d2y,'x','linewidth',2)
yyaxis right
scatter(d3x,d3y,'linewidth',2)
However, this results in the proper left and right axis colors from disappearing. All data points in the inset appear the same color, so do both the y-axes. How can I do this properly?

Respuesta aceptada

Voss
Voss el 29 de Jul. de 2022
Seems to be ok:
% initial plot
plot(rand(1,10),rand(1,10))
% make the inset
axes('Position',[0.4,0.7,0.2,0.2])
box on
% double y-axes for the inset
yyaxis left
scatter(rand(1,5),rand(1,5),'x','linewidth',2)
yyaxis right
scatter(rand(1,5),rand(1,5),'linewidth',2)
Is the code you posted the actual code you are running, which has the problem? Or is it some illustrative example code? If it's only an example, please share the actual code that has the problematic behavior.
  2 comentarios
Irem Altan
Irem Altan el 29 de Jul. de 2022
Ok so this works for me as well. In my original code, the main plot consists of 30 plots plotted on top of each other with hold on. And I use colororder(jet(30)). That seems to be the problem. For instance you could do
for i=1:30
plot(rand(1,10),rand(1,10))
hold on
end
colororder(jet(30))
% make the inset
axes('Position',[0.4,0.7,0.2,0.2])
box on
% double y-axes for the inset
yyaxis left
scatter(rand(1,5),rand(1,5),'x','linewidth',2)
yyaxis right
scatter(rand(1,5),rand(1,5),'linewidth',2)
I can change the inset plot color by passing a color argument in scatter but that doesn't fix the axis colors.
Voss
Voss el 29 de Jul. de 2022
Maybe set the colororder for the inset axes separately:
for i=1:30
plot(rand(1,10),rand(1,10))
hold on
end
colororder(jet(30))
% make the inset
ax = axes('Position',[0.4,0.7,0.2,0.2]);
colororder(ax,[0 0 1; 1 0 0]) % blue, red
box on
% double y-axes for the inset
yyaxis left
scatter(rand(1,5),rand(1,5),'x','linewidth',2)
yyaxis right
scatter(rand(1,5),rand(1,5),'linewidth',2)

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by