MATLAB For Dummies
Book image
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 authors:

John Paul Mueller is an author and technical editor with experience in application development, database management, machine learning, and deep learning. He has written hundreds of books and articles helping everyday people learn everything from networking to database management.

John Mueller has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services (AWS). Luca Massaron, a Google Developer Expert (GDE),??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques.

This article can be found in the category: