价值观在不应该出现的地方停止

时间:2018-11-14 15:35:45

标签: matlab

我的图形输入了365(天),但是在某处停止制作图形 这是我的图形结果: My Graphic

在这里,我应该得到的原始图形: Original Graphic

这是我的完整代码:

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')

2 个答案:

答案 0 :(得分:7)

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;

答案 1 :(得分:6)

您正在设置标签 text ,而不是标签 position ,让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')

enter image description here

您需要将TickValues更改为正确的天数(我假设每个月有20天),并可能更改为Xaxis的限制,为避免数据后出现不必要的空白,我将其留给读者,因为我认为询问者有500个。