Set axes and other properties with only one command

I wanted to ask how we can set the properties of all axes only with a command. I mean I don't wanna use the command set for each plot to change for example the 'FontSIze' and all the oher features.
Thank you a lot, you do always a wonderful job, best regards,
Tommaso

2 Comments

"I mean I don't wanna use the command set for each plot to change for example"
You don't need to: exactly as the set help states, you can simply supply all of the axes handles in one array as the first input argument and call set once.
Ok, but what about the different fontsize for the numbers in the axes, the legend and so on?

Sign in to comment.

 Accepted Answer

"Ok, but what about the different fontsize for the numbers in the axes, the legend and so on?"
Sure. Read the set documentation, and you will see that you can set different values for each of the handles with just one set call: " set(H,NameArray,ValueArray) specifies multiple property values using the cell arrays NameArray and ValueArray. To set n property values on each of m graphics objects, specify ValueArray as an m-by-n cell array, where m = length(H) and n is equal to the number of property names contained in NameArray."
A simple example with two objects, one property, and each object getting a different value:
ax(1) = axes(...);
ax(2) = axes(...);
set(ax,{'fontsize'},{12;20})
The second cell array must have as many columns as the number of properties you specify in the first cell array. There is no practical limit to how many objects and how many properties you can set with one set call.

2 Comments

Thank you very much, I think I got this.
But could you help me out and tell me why this piece of code doesn't work? (I tried also with Title without ' ' )
ax(1)=axes('Title');
ax(2)=axes('FontSize');
set(ax,{'fontsize'},{35,20})
Thank you again,
Tommaso
What are these lines supposed to do?:
ax(1)=axes('Title');
ax(2)=axes('FontSize');
The axes command creates an axes object, and its permitted input arguments are explained in the documentation. While there certainly are axes properties with names matching the ones you used, you did not use any (required!) values to accompany them. It is not clear what you expect the result of those commands to be.
Note that if you expect to get two separate visible axes you will need to use subplot, or create them in different figures, or use set to change their positions:
>> ax(1) = axes();
>> ax(2) = axes();
>> set(ax,{'position'},{[0.1,0.1,0.35,0.8];[0.55,0.1,0.35,0.8]})
>> saveas(gcf,'setaxes.png')
setaxes.png

Sign in to comment.

More Answers (0)

Categories

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

Tags

Asked:

on 23 Jan 2019

Edited:

on 24 Jan 2019

Community Treasure Hunt

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

Start Hunting!