Home

How to Modify the Plot Box Aspect Ratio to Change the Appearance of Your MATLAB Plot

|
|  Updated:  
2016-03-27 09:30:33
|   From The Book:  
MATLAB For Dummies
Explore Book
Buy On Amazon

MATLAB allows you to modify the plot box aspect ratio. Instead of modifying the data, the plot box aspect ratio modifies the plot box — the element that holds the plot in its entirety — as a whole. The appearance of the data still changes, but in a different way than before. The following steps get you started with this example:

Type YSource = [1, 3, 5; 3, 7, 9; 5, 7, 11]; and press Enter.

MATLAB creates a data source for you.

Type Bar1 = bar3(YSource); and press Enter.

You see a 3D bar chart appear.

Type rotate(Bar1, [0, 0, 1], 270); and press Enter.

Type rotate(Bar1, [0, 0, 1], 270); and press Enter.

The bar chart rotates so that you can see the individual bars easier.

Type pbaspect() and press Enter.

As before, you get three values: x-, y-, and z-axis. However, the numbers differ from before because now you’re working with the plot box aspect ratio and not the data aspect ratio. Here are typical output values at this point:

ans =
 2.8000 4.0000 2.4721

Type pbaspect([1.5, 1.5, 7]); and press Enter.

Type pbaspect([1.5, 1.5, 7]); and press Enter.

The differences between the data points seem immense.

Notice how changing the plot box aspect ratio affects both the plot box and the data so that the plot box no longer is able to change settings, such as the spacing between bars. What this means in particular is that you don’t have to worry about bars ending up outside the plot area and not being displayed. The bars and the plot box are now locked together.

Type pbaspect([4, 5, 1]); and press Enter.

Type pbaspect([4, 5, 1]); and press Enter.

The data points now seem closer together, even though nothing has changed in the data.

Type pbaspect(‘auto’); and press Enter.

The plot aspect returns to its original state.

About This Article

This article is from the book: 

About the book author:

John Paul Mueller is a freelance author and technical editor. He has writing in his blood, having produced 100 books and more than 600 articles to date. The topics range from networking to home security and from database management to heads-down programming. John has provided technical services to both Data Based Advisor and Coast Compute magazines.

Jim Sizemore is Professor of Physics and Engineering at Tyler Junior College. For over 25 years he s worked in the semiconductor and software industries as a process engineer, device physicist, and software developer and has been teaching college physics, engineering, and math for the last 13 years.