How do I create an axes on a figure?

I use this line
handles.axes7 = axes('Units','normalized','Position',[5.2 11.923 19.2 7.769]);
But it doesn't seem to work

 Accepted Answer

Stephen23
Stephen23 on 21 Jun 2018
Edited: Stephen23 on 21 Jun 2018
Your units and position are incongruous. If you use 'normalized' then all of the position values will (almost always) be between zero and one. This is explained in the axes properties page:
which states for normalized units: "Normalized with respect to the container, which is typically the figure or a panel. The lower left corner of the container maps to (0,0) and the upper right corner maps to (1,1)."
If (0,0) is the lower left of the figure and (1,1) is upper right of the figure, as the documentation clearly states, where do you think your axes lower left point (5.2,11.923) will be? (hint: waaaay outside the figure boundaries). And you specified the axes to be 19.2 times the width of the figure and 7.769 times as high: these axes are so huge, you would only ever see 0.67% of the axes inside the figure, even if you moved its lower-left corner so that it was visible.
Hint: if you are using normalized units then (0.5,0.5) is in the center of the figure.

7 Comments

But I got those position values from GUIDE. How to make it normal size. I want to put a logo
@Stelios Fanourakis: I never use GUIDE, because writing my own GUI code is simpler and gives me control over my GUI, so I can't help with GUIDE.
"But I got those position values from GUIDE"
What command did you use to get those values? What were the units when you got those values?
"How to make it normal size"
I don't know what "normal size" means. Do you want a specific, fixed size on the screen, or a relative size that will resize if you change the figure size? For a normalized axes something like this will get you started:
Position,[0.1,0.1,0.8,0.8]
If you want a fixed specific size then change the units to pixels/whatever and then specify the required position.
I want the size of a logo to be placed a bit lower than the middle of the figure
If I give pixel values I get a tiny logo. Need normal size of it
Stephen23
Stephen23 on 21 Jun 2018
Edited: Stephen23 on 21 Jun 2018
"If I give pixel values I get a tiny logo"
You get a tiny logo because you did not use enough pixels. Solution: use more pixels. If ten pixels is too small, then make it one hundred. MATLAB does not limit how many pixels you can use!
"Need normal size of it"
Please define what a "normal" size is. In my last comment I showed you how to use most of the figure area using normalized units: would that be a "normal" size?
To be honest I have no idea why you are setting this yourself anyway. If you want "normal" size, why not just use the "normal" default axes size, which takes up most of the figure?
Normal size for a logo. Small enough but not tiny. Still am trying to accomplish it
Stephen23
Stephen23 on 21 Jun 2018
Edited: Stephen23 on 21 Jun 2018
"Normal size for a logo."
Well, I don't know any computer that will understand that command, so you will have to figure out what a "normal size" means in some real units that computers will understand, e.g. pixels, cm, inches, etc, then set the units and position. It is that simple.

Sign in to comment.

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!