How to make inset figure with two y-axes
5 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Voss
on 29 Jul 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 Comments
Voss
on 29 Jul 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)
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!