Custom Ticks for X-Axis

10 visualizaciones (últimos 30 días)
Tyler McDonald
Tyler McDonald el 29 de Feb. de 2016
Respondida: Adam el 1 de Mzo. de 2016
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?

Respuestas (2)

Image Analyst
Image Analyst el 29 de Feb. de 2016
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.

Adam
Adam el 1 de Mzo. de 2016
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 )] )

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by