Is it possible to create a plot with tick labels as multiples of pi in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter danago
  • Start date Start date
  • Tags Tags
    Matlab Plot Scale
Click For Summary

Discussion Overview

The discussion revolves around the possibility of creating a plot in MATLAB with tick labels represented as multiples of pi, specifically on the horizontal axis. The scope includes technical explanations and practical application of MATLAB's plotting features.

Discussion Character

  • Technical explanation, Experimental/applied

Main Points Raised

  • One participant inquires about the feasibility of setting horizontal axis tick labels as multiples of pi in MATLAB.
  • Another participant suggests using the 'set' function to define the tick marks and their corresponding labels, providing a specific example of how to implement this.
  • A later reply expresses gratitude for the provided solution, indicating it meets their needs.
  • Another participant points out that MATLAB does not support TeX character sequences in tick labels, referencing MATLAB help documentation for clarification.

Areas of Agreement / Disagreement

Participants generally agree on the method to set tick marks and labels, but there is disagreement regarding the support for TeX formatting in tick labels, with one participant asserting it is not possible.

Contextual Notes

Limitations include the potential for confusion regarding the number of tick marks versus labels, as well as the specific capabilities of MATLAB regarding text formatting in tick labels.

danago
Gold Member
Messages
1,118
Reaction score
4
I want to create a plot, but want the horizontal axis to have increments as multiples of pi eg. {0, pi/2, pi, 3pi/2, ... }

Is this at all possible in matlab?
 
Physics news on Phys.org
Yes - you can set where the tick marks are on an axis:

This will control where the ticks go (use whatever range you want):
set(gca,'XTick',0:pi/2:3*pi/2)

(Note that gca returns the handle for the current set of axes)

This will control the labels for the ticks:
set(gca,'XTickLabel',{'0','pi/2','pi','3pi/2'})


So you can attach text labels to all of your tick marks - make sure that you have the correct number of labels - I think if you have more tick marks than labels, MATLAB will just cycle back through your list of labels for the extra tick marks. Also, I know that MATLAB supports some tex and latex formatting so that you could display [tex]\pi[/tex] instead of pi, but I'm not sure if that is supported for tick labels (and if it is I'd have to play around with it to figure out how that works).
 
Thanks very much, exactly what i was after :smile:
 
Unfortunately, MATLAB can't display tex characters in tick labels.

From MATLAB help - keyword: Axes properties:

...
Note that tick labels do not interpret TeX character sequences (however, the Title, XLabel, YLabel, and ZLabel properties do).
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K