How to add right ylabel with complex values (attached data and code)
1 view (last 30 days)
Show older comments
I have a matrix attached called "PF". I read the matrix and plot it using pcolor. This matrix has x-label named "x_state" and left y-axis named "DR"; both attached. I want to add ylabel to the righ axis giving the complex array called "EV" attached.
Any idea?
Thanks
clear all; clc;
PF = xlsread('PF.xlsx'); % Main data to be plotted
DR = xlsread('DR.xlsx'); % used to label left y-axis
[~, TEXT, ~] = xlsread('States.xlsx'); x_state=TEXT; % used to label x-axis
[~, TEXT, ~] = xlsread('EV.xlsx'); EV=TEXT; % I want to add these complex values to the right y-axis
pcolor(PF)
xticks(1:176);yticks(1:176);
xticklabels(x_state)
xtickangle(90)
yticklabels(num2str(DR*100))
ytickangle(0)
ylabel('DR (%)')
xlabel('States')
axis([65 96 65 96])
Answers (3)
Alex Mcaulley
on 6 Mar 2019
3 Comments
Alex Mcaulley
on 6 Mar 2019
Is this that you want?
clear all; clc;
PF = xlsread('PF.xlsx'); % Main data to be plotted
DR = xlsread('DR.xlsx'); % used to label left y-axis
[~, TEXT, ~] = xlsread('States.xlsx'); x_state=TEXT; % used to label x-axis
[~, TEXT, ~] = xlsread('EV.xlsx'); EV=TEXT; % I want to add these complex values to the right y-axis
pcolor(PF)
xticks(1:176);yticks(1:176);
xticklabels(x_state)
xtickangle(90)
yticklabels(num2str(DR*100))
ytickangle(0)
ylabel('DR (%)')
yyaxis 'right'
ax = gca;
ax.YAxis(2).TickLabels = cellfun(@num2str,EV,'UniformOutput',false);
ax.YAxis(2).TickValues=1:numel(EV);
ylabel('EV (%)')
xlabel('States')
axis([65 96 65 96])
Star Strider
on 6 Mar 2019
Try this:
x1 = sort(rand(1,10)); % Create Data
y1 = rand(1,10); % Create Data
x2 = sort(rand(1, 15)); % Create Data
y2 = rand(1, 15)+0.5; % Create Data
figure
ax = gca;
yyaxis left
plot(x1, y1)
yyaxis right
plot(x2, y2)
yt2 = ax.YAxis(2).TickValues; % Get Current Yick Values
ytv = sort(exp(1j*rand(1,7))); % Define Complex YAxis(2) Tick Values
yt2new = linspace(min(yt2), max(yt2), numel(ytv)); % Create Tick Positions Corresponding To ‘ytv’
y2lbls = sprintfc('%.3f%+.3fj', ytv); % Create Complex YAxis(2) Tick Labels Cell Array: ‘sprintfc’
y2lbls = compose('%.3f%+.3fj', ytv); % Create Complex YAxis(2) Tick Labels Cell Array: ‘compose’
ax.YAxis(2).TickValues = yt2new; % Set New Tick Values
ax.YAxis(2).TickLabels = y2lbls; % Set New Tick Labels
You already have a vector for ‘ytv’, so substitute it for my vector. (Keeping the names the same with a different vector will simplify your using my code.)
Experiment to get the result you want.
6 Comments
See Also
Categories
Find more on Geographic Plots 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!