Matlab 价值观停在不应该停的地方

Matlab 价值观停在不应该停的地方,matlab,Matlab,我有365天为我的图形输入,但在某处,它是停止制作图形 这是我的图形结果: 这里是我应该得到的原始图形: 这是我的全部代码: days = 1:365; %Formulas of the Equation of Time earth_tilt = -7.655*sin(2*pi*days/365) elliptical_orbit = 9.873*sin(4*pi*days/365+3.588) time_variation = earth_tilt + elliptical_orbit p

我有365天为我的图形输入,但在某处,它是停止制作图形 这是我的图形结果:

这里是我应该得到的原始图形:

这是我的全部代码:

days = 1:365;
%Formulas of the Equation of Time
earth_tilt = -7.655*sin(2*pi*days/365)
elliptical_orbit = 9.873*sin(4*pi*days/365+3.588)
time_variation = earth_tilt + elliptical_orbit
plot(days,earth_tilt,'g--')
hold on
plot(days,elliptical_orbit,'r-.')
plot(days,time_variation,'black')
ax = gca;
ax.XAxisLocation = 'origin';
ax.XAxis.TickLabels = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'}';
ax.XAxis.Limits = [0 500];
title('Time Variation')
xlabel('Day of The Year','FontWeight','bold')
ylabel('Minutes','FontWeight','bold')
legend({'Earth Elliptic Orbit','Tilt of Earth Axis','Orbit+Tilt'},'FontSize',14)
% Location information of legend
set(legend, 'Location', 'NorthWest')
您设置的是标签文本,而不是标签位置,让MATLAB选择它想要的位置。具体而言,您的刻度位于:

ax.XAxis.TickValues

ans =

     0    50   100   150   200   250   300   350   400   450   500
与您输入的标签不对应。更改这些位置:

days = 1:365;
%Formulas of the Equation of Time
earth_tilt = -7.655*sin(2*pi*days/365)
elliptical_orbit = 9.873*sin(4*pi*days/365+3.588)
time_variation = earth_tilt + elliptical_orbit
plot(days,earth_tilt,'g--')
hold on
plot(days,elliptical_orbit,'r-.')
plot(days,time_variation,'black')
ax = gca;
ax.XAxisLocation = 'origin';
ax.XAxis.TickLabels = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'}';
ax.XAxis.Limits = [0 500];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ax.XAxis.TickValues=[0:30:360]; % yeah its not 100% right, change it to @Brice's answer data.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

title('Time Variation')
xlabel('Day of The Year','FontWeight','bold')
ylabel('Minutes','FontWeight','bold')
legend({'Earth Elliptic Orbit','Tilt of Earth Axis','Orbit+Tilt'},'FontSize',14)
% Location information of legend
set(legend, 'Location', 'NorthWest')
您需要将tickValue更改为正确的天数,我假设每个月有20天,可能还有Xaxis的限制,为了避免数据后出现不必要的空白,我将其留给读者,因为我假设询问者出于某种原因有500天。

您设置的是标签文本,而不是标签位置,让MATLAB选择它想要的位置。具体而言,您的刻度位于:

ax.XAxis.TickValues

ans =

     0    50   100   150   200   250   300   350   400   450   500
ax.XAxis.TickLabels = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'}';
与您输入的标签不对应。更改这些位置:

days = 1:365;
%Formulas of the Equation of Time
earth_tilt = -7.655*sin(2*pi*days/365)
elliptical_orbit = 9.873*sin(4*pi*days/365+3.588)
time_variation = earth_tilt + elliptical_orbit
plot(days,earth_tilt,'g--')
hold on
plot(days,elliptical_orbit,'r-.')
plot(days,time_variation,'black')
ax = gca;
ax.XAxisLocation = 'origin';
ax.XAxis.TickLabels = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'}';
ax.XAxis.Limits = [0 500];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ax.XAxis.TickValues=[0:30:360]; % yeah its not 100% right, change it to @Brice's answer data.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

title('Time Variation')
xlabel('Day of The Year','FontWeight','bold')
ylabel('Minutes','FontWeight','bold')
legend({'Earth Elliptic Orbit','Tilt of Earth Axis','Orbit+Tilt'},'FontSize',14)
% Location information of legend
set(legend, 'Location', 'NorthWest')
您需要将tickValue更改为正确的天数,我假设每个月有20天,可能还有Xaxis的限制,为了避免数据后出现不必要的空白,我将其留给读者,因为我假设询问者出于某种原因有500天

ax.XAxis.TickLabels = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'}';
标签名称已更改,但没有提及这些标签应显示在何处。默认情况下,它们将均匀分布在图形ax.XAxis.Limits=[0 500]的500天内

正确设置刻度位置

ax.XAxis.Tick=cumsum([31 28 31 30 31 30 31 31 30 31 30 31])-30;
标签名称已更改,但没有提及这些标签应显示在何处。默认情况下,它们将均匀分布在图形ax.XAxis.Limits=[0 500]的500天内

正确设置刻度位置

ax.XAxis.Tick=cumsum([31 28 31 30 31 30 31 31 30 31 30 31])-30;

我定义滴答声时,你不那么懒:我定义滴答声时,你不那么懒:P@DennisJaheruddin纯粹为了形象化的目的,这并不意味着我的答案是错误的。修改以显示它不是问题这仍然不会导致问题的最终图片,因为它会留下白色space@DennisJaheruddin是的,XD我改变了它,因为你说我改变了范围,以表明改变范围不是解决方案,而只是对可视化的改进。现在,我的xlimit与询问者没有区别,标签位于正确的位置。@DennisJaheruddin纯粹出于可视化目的,它不会使我的答案出错。修改以显示它不是问题这仍然不会导致问题的最终图片,因为它会留下白色space@DennisJaheruddin是的,XD我改变了它,因为你说我改变了范围,以表明改变范围不是解决方案,而只是对可视化的改进。现在,我的xlimit与询问者没有区别,标签位于正确的位置。