Search code examples
plotoctave

Change x axis to scale with pi and not numbers


I want to create the plot of cos(x) and sin(x) in Octave. I have learned how to change things such as xlabel and xlim, however I can’t find how to change from having numbers (e.g 1, 2, 3) to having pi terms (-pi,-pi/2 and such). I would also appreciate if you can explain me how to do that. Here is a picture of what I want to do in case my english confused you.

enter image description here


Solution

  • In Matlab you can do something like this:

    set(gca,'XTick',-pi:pi/2:pi)
    set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'})
    

    As you can see here: http://www.mathworks.com/help/matlab/creating_plots/setting-axis-parameters.html

    This should work in Octave as well.

    Also I haven't tested this but to get the actual Pi symbol you might try:

    set(gca,'XTickLabel',{'-p','-p/2','0','p/2','p'}, 'fontname','symbol')
    

    Otherwise you can try and see if this Matlab FEX submission will work for you: http://www.mathworks.com/matlabcentral/fileexchange/15986