Bar plot in Matlab with specified values on the x-axis

  • Context: MATLAB 
  • Thread starter Thread starter hokhani
  • Start date Start date
  • Tags Tags
    Matlab Plot
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 3K views
hokhani
Messages
606
Reaction score
22
In the plot below
Code:
x=.1:.01:.2;
y=5:15;
bar(x,y)
I like all the values of x to be displayed on the x-axis. For example by plotting this bar, the values of x=0.11,0.13, 0.15, 0.17, 0.19 are not displayed on the x-axis. I appreciate any help.
 
Physics news on Phys.org
In the plot window, you can select Edit -> Axes Properties... There you can set where tics appear.
 
http://www.mathworks.com/help/matlab/ref/axes-properties.html?searchHighlight=xtick

x=.1:.01:.2;
y=5:15;
bar(x,y)

After plotting, you can create a handle to the axes object (gca stands for, "get current axes") and then change the XTick property to whatever you'd like, such as your original x values:
ax = gca;
ax.XTick = x;

Note: this assumes you're using R2014b+. For older releases you use the get/set functions to fetch or change properties of the axes.