Search code examples
matlabplotoctave

How to label points on X axis for a plot in Octave/MATLAB?


I want to plot an electronic band structure like the following in GNU Octave.

enter image description here

I have already generated the graph (I made a big linspace k_values for X axis and have values of corresponding energies, but I am unsure how to label the points in X axis). Right now I am plotting like this.

plot(k_values,band1,'color','black')
hold on
plot(k_values,band2,'color','red')

As usual, it is showing numbers along the X axis.

  1. How to remove the numbers from X axis and label certain points (such as Gamma, X, Y) just as the above figure? I know the corresponding value of X coordinate of those points.
  2. How to put vertical grid lines at those points?

Solution

  • It can be implemented with xtick.

        plot(k_values,band1,'color','black')
        hold on
        plot(k_values,band2,'color','red')
        set(gca,'xtick',[x1 x2 x3 x4 x5 x6]); %Coordinates of W, Gamma, X, W etc.
        %set(gca, 'xticklabel',({'W','\Gamma','X','W','L', 'Gamma'})); 
        %Note: This did not show Greek Gamma did in Octave 4.4 after printing to a pdf 
        %so see alternate method below
        set(gca, 'xticklabel',({'','','','','','',''}));
    
        text(x1,-12, '$W$', 'fontsize', 30) 
        %Note "$\Gamma$" won't work, and xticklabel cannot recognize \Gamma
        text(x2,-12, '$\Gamma$', 'fontsize', 30)
        text(x3,-12, '$X$', 'fontsize', 30)
        text(x4,-12, '$W$', 'fontsize', 30)
        text(x5,-12, '$L$', 'fontsize', 30)
        text(x6,-12, '$\Gamma$', 'fontsize', 30)