Creating a plot with 2 x -axis

Hello everyone,
I would like to create a bar or a line plot with two x-axes from the xlsx file attached to this question. How do I do this? I would like the droplet size to be on the bottom x-axis and the distance to be on the top x-axis with the frequency on the y-axis. What is the easy way to do this?
Thanks

Answers (1)

Sara Boznik
Sara Boznik on 16 Aug 2020
Read about plotyy.

5 Comments

But I need two x-axis and not y-axis
AX = plotyy(...);
set(AX(2),'XAxisLocation','Top')
num = xlsread("Raw data.xlsx") ;
R = num(:,1) ; % sizes
x = linspace(0,1.18,length(R)) ;
y = zeros(size(R)) ;
R = R(end:-1:1) ; % Reverse R
subplot(2,1,1)
scatter(x,y,R,R,'filled','MarkerEdgeColor',[0 .5 .5],...
'MarkerFaceColor',[0 .7 .7],...
'LineWidth',1.5)
xlabel('Distance (m)')
xlh = xlabel('Distance (m)');
xlh.Position(2) = xlh.Position(2) - 1.0; % move the label 0.1 data-units further down
axh = axes;
xlh = xlabel('Distance (m)');
xlh.Position(2) = xlh.Position(2) - abs(xlh.Position(2) * 0.1);
ylabel('Height (m)')
ylim([0 2])
hold on
scatter(0,1.7,3000,'filled','MarkerEdgeColor',[0 .5 .5],...
'MarkerFaceColor',[0 .7 .7],...
'LineWidth',1.5)
subplot (2,1,2)
plot(DropletSizemicrons,Frequency,'-b.','Markersize',25)
xlabel('Droplet size [microns]')
set ( gca, 'xdir', 'reverse' )
AX = plotyy(...);
set(AX(2),'XAxisLocation','Top')
ylabel('Frequency')
that's currently my code. I added the command you told in the second last line but it doesn't seem to be working when I run it
AX=plotyy(DropletSizemicrons,Frequency,'-b.','Markersize',25)
xlabel('Droplet size [microns]')
set ( gca, 'xdir', 'reverse' )
set(AX(2),'XAxisLocation','Top')
ylabel('Frequency')
I get error with Unrecognized function or variable 'DropletSizemicrons'.
Error in plotyy>fevalfun (line 376)
h = feval(func,x,y);
Error in plotyy (line 78)
[h1,ax(1)] = fevalfun(fun1,ax(1),x1,y1,caxspecified);
Error in Untitled4 (line 25)
AX= plotyy(DropletSizemicrons,Frequency,'-b.','Markersize',25);
I get this error. DropletSizemicrons is the first column in the excel sheet which I imported using the import data function and then converted into column vectors. Apparently, it's an error in the plotyy function

Sign in to comment.

Categories

Tags

Asked:

on 16 Aug 2020

Commented:

on 16 Aug 2020

Community Treasure Hunt

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

Start Hunting!