MATLAB: How to insert special tick labels onto an axis

labelsplotticks

I have a vector of years and corresponding depths which I would like to plot in a bar chart. The years are labelled on the x axis. Say these years are 1800, 1820, 1840, 1860, …., 1980. The first data point is at 1818. However, I would like to label one special year of 1788 on the x-axis before these automatic labels, with the y values being 0 for each x-axis point until 1818, which is the first one.
I have added the point (1788,0) to my data set which I am plotting, however I am having trouble adding the label at an appropriate distance relative to all the other labels.
This is what I have previously tried:
set(gca, 'xticklabel', {1788, 1800, 1820, 1840, 1860, 1880, 1900, 1920, 1940, 1960, 1980}) However, this gives me the label '1788' on the x-axis at the same spacing as all the other labels, but I want it to be positioned at the appropriate scale.
I have also tried With xticksat= [1788] but this doesn't work at all and gives me an error when I try to run the function.
Does anybody have any suggestions?
Help would be very much appreciated.

Best Answer

It may be necessary to define the 'XTick' locations as well.
See if this does what you want:
x = [1788, 1800, 1820, 1840, 1860, 1880, 1900, 1920, 1940, 1960, 1980];
y = randi(25, 11, 1); % Created Data
figure(1)
bar(x, y)
set(gca, 'XTick', x, 'xticklabel', {1788, 1800, 1820, 1840, 1860, 1880, 1900, 1920, 1940, 1960, 1980})
Related Question