Plot with linspace: display x-tick values not index

  • Thread starter skynelson
  • Start date
  • #1
skynelson
57
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
 

Answers and Replies

  • #2
jasonRF
Science Advisor
Gold Member
1,508
576
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
 
  • #3
hdp12
68
2
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
 
  • #4
skynelson
57
4
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.
 
  • #5
skynelson
57
4
Thanks hdp12 for the response! This is a good approach for more specific control over layout.
 

Suggested for: Plot with linspace: display x-tick values not index

  • Last Post
Replies
1
Views
409
  • Last Post
Replies
4
Views
1K
Replies
2
Views
1K
Replies
0
Views
409
  • Last Post
Replies
1
Views
460
  • Last Post
Replies
2
Views
493
  • Last Post
Replies
2
Views
692
  • Last Post
Replies
1
Views
608
  • Last Post
Replies
11
Views
2K
  • Last Post
Replies
7
Views
694
Top