How can I control decimal in plot with four axes?

조회 수: 2 (최근 30일)
Mohammed Ali
Mohammed Ali 2021년 1월 4일
답변: Timo Dietz 2021년 1월 4일
I need to plot data with different scales but I am not able to control the decimal in the right and top axes. I tried many ways without succeeding. When I applied that for right axis, the values of right axis become similar to the left values which is not correct. Also the legend is not shown.
clc
clear all
t=[0:1:3600];
d=1.94444*t;
f=figure (1)
ax1 = gca;
plot(t,d)
axis([0 3000 0 6000])
grid on
set(gca,'GridLineStyle',':')
xt = get(ax1,'XTick')
yt = get(ax1,'YTick')
ax2 = copyobj(ax1,f);
set(ax2,'XAxisLocation','top')
set(ax2,'YAxisLocation','right')
xxt= xt/60
yyt = 3.28084*yt
set(ax2,'XTickLabel',xxt)
set(ax2,'YTickLabel',yyt)
%ytickformat(ax2,'%.2f')
legend('No. 1')
xlabel(ax1,'time (s)')
ylabel(ax1,'distance (m)')
xlabel(ax2,'time (min)')
ylabel(ax2,'distance (ft)')

답변 (1개)

Timo Dietz
Timo Dietz 2021년 1월 4일
I don't think that it's possible what you want to achieve.
A second y axis can be activated with yyaxis or plotyy (same x scaling). What you are currently doing is
plotting two graphs on top of each other and the legend is covered by the top layer.
This is why you do not see it.

카테고리

Help CenterFile Exchange에서 Axes Appearance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by