I drew two curves in a plot; permeability and impedance. And then tried to copy & paste the same-type curves to compare 1:1. But the curve in yyaxis right is linked to yyaxis left, and I don't know how to link it to yyaxis right.
I tried to change the y axis of the copied/pasted curve from left to right. I'd like to see/compare two permeability curves in yyaxis left and two impedance curves in yyaxis right.
I drew two curves in a plot; permeability and impedance. And then tried to copy & paste the same-type curves to compare 1:1. But the curve in yyaxis right is linked to yyaxis left, and I don't know how to link it to yyaxis right.
I tried to change the y axis of the copied/pasted curve from left to right. I'd like to see/compare two permeability curves in yyaxis left and two impedance curves in yyaxis right.
Share Improve this question asked Feb 7 at 16:32 Sang Min KimSang Min Kim 11 bronze badge 1- Please provide enough code so others can better understand or reproduce the problem. – Community Bot Commented Feb 7 at 19:26
1 Answer
Reset to default 0The issue is that if you want to copy and paste a curve, the best way is to manually extract the original data and then redraw it using yyaxis right in a new plot or in the same plot, instead of directly copying and pasting!
You should provide some data and code to clarify your meaning. In the absence of that, let’s assume I am using the data and code below to illustrate your point, which might not be accurate, so please point it out.
%% Generate sample data (Permeability & Impedance)
% Assume permeability (left axis) and impedance (right axis) vary over time
x1 = 0:0.1:10; % Time axis (permeability)
y1 = 10*sin(x1) + x1; % Permeability data (sine wave with linear growth)
x2 = 0:0.1:10; % Time axis (impedance)
y2 = 5*cos(x2) + 2*x2; % Impedance data (cosine wave with linear growth)
%% Step 1: Plot the original graph (left axis: permeability, right axis: impedance)
figure(1);
clf;
% Left axis: Permeability
yyaxis left;
h_permeability = plot(x1, y1, 'b-', 'LineWidth', 1.5, 'DisplayName', 'Permeability');
ylabel('Permeability (Unit)');
ylim([min(y1)-5, max(y1)+5]);
% Right axis: Impedance
yyaxis right;
h_impedance = plot(x2, y2, 'r--', 'LineWidth', 1.5, 'DisplayName', 'Impedance');
ylabel('Impedance (Ω)');
ylim([min(y2)-5, max(y2)+5]);
% Add title and legend
title('Original Data: Permeability vs. Impedance');
legend('Location', 'northwest');
grid on;
%% Step 2: Extract data and generate a comparison graph (copy curves to the same axis)
figure(2);
clf;
% Left axis: Plot two permeability curves
yyaxis left;
hold on;
plot(x1, y1, 'b-', 'LineWidth', 1.5, 'DisplayName', 'Permeability 1');
plot(x1, y1 + 8, 'b:', 'LineWidth', 1.5, 'DisplayName', 'Permeability 2 (Shifted)'); % Copy and shift
ylabel('Permeability (Unit)');
ylim([min(y1)-5, max(y1)+15]); % Adjust range to accommodate the new curve
% Right axis: Plot two impedance curves
yyaxis right;
hold on;
plot(x2, y2, 'r--', 'LineWidth', 1.5, 'DisplayName', 'Impedance 1');
plot(x2, y2 * 0.6, 'r-.', 'LineWidth', 1.5, 'DisplayName', 'Impedance 2 (Scaled)'); % Copy and scale
ylabel('Impedance (Ω)');
ylim([min(y2)-5, max(y2)+5]);
% Add title, legend, and grid
title('Comparison: Two Permeability & Two Impedance Curves');
legend('Location', 'northwest');
grid on;