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

  • MATLAB
  • Thread starter hokhani
  • Start date
  • Tags
    Matlab Plot
In summary, the conversation discusses how to display all values of x on the x-axis in a plot, including those that are not currently displayed. This can be done by accessing the axes properties and setting the XTick property.
  • #1
hokhani
488
8
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
  • #2
In the plot window, you can select Edit -> Axes Properties... There you can set where tics appear.
 
  • #3
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.
 

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

1. How do I create a bar plot in Matlab with specified values on the x-axis?

To create a bar plot with specified values on the x-axis in Matlab, you can use the function bar(x,y), where x is a vector containing the x-values and y is a vector containing the corresponding y-values.

2. Can I customize the appearance of the bar plot in Matlab?

Yes, you can customize the appearance of the bar plot in Matlab by using additional input arguments in the bar function. For example, you can specify the color, width, and style of the bars using the 'FaceColor', 'BarWidth', and 'LineStyle' arguments, respectively.

3. How do I label the x-axis in a bar plot in Matlab?

To label the x-axis in a bar plot in Matlab, you can use the xlabel function. Simply pass in the desired label as a string to the function, e.g. xlabel('Months'). You can also customize the font, size, and position of the label using additional input arguments.

4. Can I add a title to my bar plot in Matlab?

Yes, you can add a title to your bar plot in Matlab using the title function. Again, pass in the desired title as a string to the function, e.g. title('Sales by Month'). You can also customize the font, size, and position of the title using additional input arguments.

5. How do I save my bar plot in Matlab as an image file?

To save your bar plot in Matlab as an image file, you can use the saveas function. Simply pass in the figure handle and the desired file name as arguments, e.g. saveas(fig, 'myplot.png'). You can also specify the file format, resolution, and other settings using additional input arguments.

Similar threads

Replies
8
Views
647
Replies
4
Views
1K
Replies
1
Views
2K
Replies
4
Views
2K
Replies
1
Views
1K
Replies
11
Views
2K
Replies
10
Views
2K
Replies
2
Views
3K
Replies
1
Views
1K
Replies
1
Views
571
Back
Top