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

  • Thread starter Thread starter hokhani
  • Start date Start date
  • Tags Tags
    Matlab Plot
Click For Summary
To display all specified x-axis values in a MATLAB bar plot, users can modify the XTick property of the axes object. After creating the bar plot, the current axes can be accessed using the command "ax = gca," followed by setting "ax.XTick = x" to include all desired x values. This method is applicable for MATLAB R2014b and newer versions; older versions require using get/set functions for property adjustments. Additionally, users can manually adjust tick settings through the Axes Properties menu in the plot window. Properly configuring the x-axis enhances the clarity and accuracy of the bar plot visualization.
hokhani
Messages
574
Reaction score
20
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.
 

Similar threads

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