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
Click For Summary
SUMMARY

This discussion focuses on customizing the x-axis values in a bar plot using MATLAB. Users can display specific x-axis values by modifying the XTick property of the axes object. The provided code snippets utilize MATLAB's bar function and the gca function to access and adjust the current axes. This method is applicable for MATLAB R2014b and later versions, while older versions require the use of get/set functions for property adjustments.

PREREQUISITES
  • Familiarity with MATLAB programming environment
  • Understanding of bar plots in MATLAB
  • Knowledge of axes properties in MATLAB
  • Experience with MATLAB R2014b or later
NEXT STEPS
  • Learn how to use MATLAB's get/set functions for axes properties in older versions
  • Explore MATLAB's documentation on axes properties for advanced customization
  • Investigate additional plotting functions in MATLAB for enhanced data visualization
  • Practice creating bar plots with varying x-axis configurations in MATLAB
USEFUL FOR

This discussion is beneficial for MATLAB users, data analysts, and researchers looking to enhance their data visualization skills, specifically in customizing bar plots and managing axes properties.

hokhani
Messages
601
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.
 

Similar threads

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