Custom Ticks for X-Axis
10 次查看(过去 30 天)
显示 更早的评论
I have some financial which I plot using the datetime function.
x_dates = datetime(IQFeedTimeseriesData(:,1));
y_values = str2double(IQFeedTimeseriesData(:,2));
p = plot(x_dates, y_values, 'DatetimeTickFormat','MM/dd h:mm');
which gives me the image
Clearly I would like to break the chart so the data from when the market was closed doesn't show. I've attempted to use from the "break axis" community written apps but none seem to work well, especially when there are multiple breaks.
Previously I have plotted the Y-data against a sequence of numbers (1..2..3..etc) (which gets rid of the break)
then instead of allowing the x-axis being labeled 1, 2, 3, etc. I wrote my own labels (using the correct dates) and overwrote the default axis ticks.
Is this possible in Matlab?
0 个评论
回答(2 个)
Image Analyst
2016-2-29
Yes, you can. Just look up tick marks in the help.
ax = gca;
ax.XTickLabel = DateStrings; % A cell array of strings.
ax.XTickLabelRotation = -75; % Slant them so they don't overlap.
0 个评论
Adam
2016-3-1
You can edit the 'XTickLabel' property of axes to include whatever you want, provided you make sure it is of the same length as the number of ticks (in 'XTick'). It won't crash if the number of elements aren't the same, but it will either miss out the extra ticks or wrap around to the start if there are not enough.
In terms of plotting only some of your data you can do this easy using indexing
e.g.
plot( [x( 1:20 ) x( 35:50 )], [y( 1:20 ) y( 35:50 )] )
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!