필터 지우기
필터 지우기

Plotting a scatter plot in log-log scale

조회 수: 51 (최근 30일)
Kashif Naukhez
Kashif Naukhez 2023년 4월 1일
댓글: Kashif Naukhez 2023년 4월 1일
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?
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2023년 4월 1일
Do you want to remove the ticks on the upper y axis and right x axis?
Kashif Naukhez
Kashif Naukhez 2023년 4월 1일
편집: Kashif Naukhez 2023년 4월 1일
Yes exactly as can be seen in the figure.

댓글을 달려면 로그인하십시오.

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 4월 1일
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.
  댓글 수: 1
Kashif Naukhez
Kashif Naukhez 2023년 4월 1일
Thanks, the code worked!!!
After saving the figure, the results are acceptable

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by