Plotting a scatter plot in log-log scale
51 views (last 30 days)
Show older comments
Kashif Naukhez
on 1 Apr 2023
Commented: Kashif Naukhez
on 1 Apr 2023
I have plotted a scatter plot in log-log scale using the code
A=readmatrix('LVD_AE.xlsx','Sheet',2);
x=A(:,1);
y=A(:,2);
sz = 15;
scatter(x,y,sz,'MarkerEdgeColor','k','MarkerFaceColor',[0 1 0],'LineWidth',1)
hold on
x1=A(:,3);
y1=A(:,4);
sz = 15;
scatter(x1,y1,sz,'MarkerEdgeColor','k','MarkerFaceColor',[1 0 0],'LineWidth',1)
hold on
x2=A(:,5);
y2=A(:,6);
sz = 15;
scatter(x2,y2,sz,'MarkerEdgeColor','k','MarkerFaceColor',[0 0 1],'LineWidth',1)
hold on
x3=A(:,7);
y3=A(:,8);
sz = 15;
scatter(x3,y3,sz,'MarkerEdgeColor','k','MarkerFaceColor',[1 0 1],'LineWidth',1)
hold on
x4=A(:,9);
y4=A(:,10);
sz = 15;
scatter(x4,y4,sz,'MarkerEdgeColor','k','MarkerFaceColor',[0 0.4470 0.7410],'LineWidth',1)
hold on
x5=A(:,11);
y5=A(:,12);
sz = 15;
scatter(x5,y5,sz,'MarkerEdgeColor','k','MarkerFaceColor',[0.8500 0.3250 0.0980],'LineWidth',1)
hold on
x6=A(:,13);
y6=A(:,14);
sz = 15;
scatter(x6,y6,sz,'MarkerEdgeColor','k','MarkerFaceColor',[0.4660 0.6740 0.1880],'LineWidth',1)
hold on
x7=A(:,15);
y7=A(:,16);
sz = 15;
scatter(x7,y7,sz,'MarkerEdgeColor','k','MarkerFaceColor',[0.6350 0.0780 0.1840],'LineWidth',1)
hold on
legend('Events group 1','Events group 2','Events group 3','Events group 4','Events group 5','Events group 6','Events group 7','Events group 8')
xlabel("Inter-event times (s)")
ylabel("Normalized cumulative distribution")
set(gca,'xscale','log','yscale','log','fontsize',14,'fontname','Times','fontweight','bold','linewidth',1)
xlim([10^-5 10^1])
box on
But I am getting the log scale on right yaxis as well as top x axis as shown in the image.
How to remove this log scale on right y axis and top x axis?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1342279/image.jpeg)
2 Comments
Accepted Answer
Dyuman Joshi
on 1 Apr 2023
It is not possible to edit the top and right axis ticks separately as all axis are configured together.
There is a workaround -
%Also, you can club the plot commands together in a loop
sz=15;
%define colors as a matrix
color = [0 1 0; 1 0 0; 0 0 1; 1 0 1; 0 0.4470 0.7410; 0.8500 0.3250 0.0980; 0.4660 0.6740 0.1880; 0.6350 0.0780 0.1840];
for k=1:2:15
scatter(A(:,k),A(:,k+1),sz,'MarkerEdgeColor','k','MarkerFaceColor',color(ceil(k/2),:),'LineWidth',1)
hold on
end
%legend('Events group 1','Events group 2','Events group 3','Events group 4','Events group 5','Events group 6','Events group 7','Events group 8')
%xlabel("Inter-event times (s)")
%ylabel("Normalized cumulative distribution")
xlim([10^-5 10^1])
ax1 = gca;
set(ax1,'xscale','log','yscale','log','fontsize',14,'fontname','Times','fontweight','bold','linewidth',1)
box off
ax2 = axes('Position', get(ax1, 'Position'), 'FontSize', 10,...
'Color','None','XColor','k','YColor','k', 'LineWidth', 1,...
'XAxisLocation','top', 'XTick', [],...
'YAxisLocation','right', 'YTick', []);
linkaxes([ax1, ax2])
However, if you are trying to save the figure you might not obtain the best result.
More Answers (0)
See Also
Categories
Find more on Axis Labels 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!