Plot with linspace: display x-tick values not index

  • Thread starter Thread starter skynelson
  • Start date Start date
  • Tags Tags
    Index Plot
Click For Summary

Discussion Overview

The discussion revolves around how to modify the x-axis tick values in a MATLAB plot generated using the linspace function. Participants explore methods to display the x-axis values from 0 to 1 instead of the default index range from 1 to 1000.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant expresses a desire to change the x-axis tick labels from index numbers to values generated by linspace, specifically from 0 to 1.
  • Another participant suggests including the vector W directly in the plot command to achieve the desired x-axis representation.
  • A different approach is proposed, where the x-tick values and labels are manually set using the properties of the plot object.
  • Participants confirm that the discussion pertains to MATLAB, with one expressing satisfaction at finding a straightforward syntactical solution.

Areas of Agreement / Disagreement

Participants generally agree on the methods to modify the x-axis tick values in MATLAB, with multiple approaches being discussed without any indication of disagreement.

Contextual Notes

Some participants provide specific code snippets, but the discussion does not resolve any potential limitations or assumptions regarding the implementation of these methods.

Who May Find This Useful

Individuals working with MATLAB who are interested in customizing plot axes, particularly those using linspace for data generation.

skynelson
Messages
57
Reaction score
4
I want my graph to display the tick values along the x-axis, instead of the index number.
Because I use linspace, my data goes from 0 to 1, but my index ranges from 1 to 1000.
My plot labels the x-axis from 1 to 1000, by default. I want to change the default (or just program it) to display 0 to 1, so it looks like a physics graph. Any help much appreciated, thanks!
Code:
T = 4;
W = linspace(0, 1, 1000);
plot(sin(T*2*pi*W+1E-8)./(2*pi*W + 1E-8));

labelsXaxisExample.jpg
 
Physics news on Phys.org
This looks like Matlab to me - is that correct? If so, you just include the vector W insdied the plot command

plot(W, sin(T*2*pi*W+1E-8)./(2*pi*W + 1E-8));

jason
 
Code:
A = plot(sin(T*2*pi*W+1E-8)./(2*pi*W + 1E-8));

A.Parent.XTick = [0:100:1000];
A.Parent.XTickLabel = {'0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1'};

1610980510344.png
 
  • Like
Likes   Reactions: skynelson
jasonRF said:
This looks like Matlab to me - is that correct? If so, you just include the vector W insdied the plot command

plot(W, sin(T*2*pi*W+1E-8)./(2*pi*W + 1E-8));

jason
Yes, That's it! And yes, MATLAB. I figured there was a straightforward syntactical approach. Thanks Jason.
 
Thanks hdp12 for the response! This is a good approach for more specific control over layout.
 
  • Like
Likes   Reactions: hdp12

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K