Problem Explicitly Defining a Plot Area

I am trying to figure out how to explicitly define the area and axes location for a plot. I've looked through this link:
but I haven't had much success, yet. I'm using this code to set my plot area and axis locations:
fig = figure('units','normalized','OuterPosition',[0 0 1 1],'InnerPosition',[0.1 0.1 0.8 0.8],'Position','TightInset');
I want to know the locations of my axes because I'm also going to add annotations for multiple sets of data, and the locations of those annotations will need to be set programmatically.
This code produces the following error:
Error using figure
Value must be numeric and finite
Error in plot_test_model_chamber_wse (line 14)
fig = figure('units','normalized','OuterPosition',[0 0 1 1],'InnerPosition',[0.1 0.1 0.8 0.8],'Position','TightInset');
Can someone please help me fix this error, so I can define my plot area like I need?

 Accepted Answer

The problem is the 'Position','TightInset' name-value pair. The 'Position' property value must be a four-element vector. The 'TightInset' property is one of the Axes Properties, not one of the Figure Properties.
fig = figure('Units','normalized','OuterPosition',[0 0 1 1],'InnerPosition',[0.1 0.1 0.8 0.8]);
.

4 Comments

Allen Hammack’s Answer became this Comment —
Thank you for helping!
Your suggestion fixed the problem causing the error message. Ultimately, what I'm trying to do is reduce the size of the "empty" space around my plot. From what I can tell from the foums, the "InnerPosition" setting is how I can set the size of this empty border. I want to reduce the size of this empty border because when I export the plot as a picture and place that picture in a document, the plot area is smaller than I want.
Do you have any suggestions for how I can fix this problem?
My pleasure!
This actually seems to me as more of a Axes Properties issue than a Figure Properties issue, unless the issue is where it appears on the monitor.
I generally plot data without any preconditions. Then, I get the relevant ‘position’ values and tweak them until I get the result I want. (This is generally to avoid squashing the tick labels together, although occasionally for other reasons.) To do that, in most instances I initially leave the first two elements of the relevant ‘position’ vector (left, lower) in each situation alone and adjust the others (width, height) to get the result I want. Then, I adjust the (left, lower) to put it back in the position where I want it. That’s just easier for me. It sometimes takes a few iterations to get it the way I want it, however I’m almost always satisfied with the final result.
Unfortunately, this is iterative and interactive in every situation and so not code I can readily share.
.
Thank you! With your suggestions, I can iterate to get the plot to look like what I want!
As always, my pleasure!
.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!