A function to set common properties for all open figures

Hi,
As said in the title, I want to creat a function that imposes the same setting for all open figures. By far, I managed to do:
function SetFigureDefaults
set(findall(gcf,'-property','FontSize'),'FontSize',18)
set(findall(gcf,'-property','LineWidth'),'LineWidth',2)
end
And that works. However, I am struggling with everything related with the text interpreter. I was repeating the following lines for each figure
colorbar('TickLabelInterpreter', 'latex')
set(groot,'defaulttextinterpreter','latex');
set(groot, 'defaultLegendInterpreter','latex');
Now, I want to use them with findall feature. I want that ALL axis ticks and ALL colorbar annotations (ticks and labels) become of latex form. How shall I do that ?
Thanks for your help,
Mary

 採用された回答

Adam Danz
Adam Danz 2020 年 10 月 5 日

0 投票

h = findall(0, '-property', 'TickLabelInterpreter');
set(h, 'TickLabelInterpreter', 'Latex')

19 件のコメント

Mary
Mary 2020 年 10 月 5 日
Thanks. That works.
Is there any way to make the legend and the ticks of all colorbars in latex too ?
and "axis tight" and "box off" all open figures ?
Mary
Mary 2020 年 10 月 5 日
and make all the legends transparent ?
I was applying the following code to each figure separetly. It would be nice to have something that could be applied to all figures.
lh = legend
set(lh)
set(lh,'Box','off');
Walter Roberson
Walter Roberson 2020 年 10 月 5 日
set(findobj('type', 'legend'), 'Interpreter', 'latex', 'Box', 'off')
Mary
Mary 2020 年 10 月 5 日
Thanks Walter. That works.
Mary
Mary 2020 年 10 月 5 日
Now, it only remains to have access to the colorbar's legend and make latex the interpreter.
Adam Danz
Adam Danz 2020 年 10 月 5 日
Given Walter's example of finding legend handles, how do you think you could find a colorbar handle?
Mary
Mary 2020 年 10 月 5 日
Based on his comment, I tried the following
set(findall(gcf,'type','ColorBar'),'Interpreter', 'Latex')
but it did not work
Adam Danz
Adam Danz 2020 年 10 月 5 日
You successfully found the colobar handle but colorbars do not have an "interpreter" property as the error message indicates.
Error using matlab.graphics.illustration.ColorBar/set
Unrecognized property Interpreter for class ColorBar. % <-----
Colorbars do, however have a TickLabelInterpreter property.
Walter Roberson
Walter Roberson 2020 年 10 月 5 日
set(findall(gcf,'type','ColorBar'),'TickLabelInterpreter', 'Latex')
Mary
Mary 2020 年 10 月 7 日
Thanks Walter. But I don't know why that is not working for me.
Adam Danz
Adam Danz 2020 年 10 月 7 日
Does findall(gcf,'type','ColorBar') return anything?
Do you have multiple figures open and gcf is operating on the wrong figure?
What version of Matlab are you running (I doubt it's version related but always good to know)?
Mary
Mary 2020 年 10 月 12 日
The version is 2019a.
I have multiple figures being open and gcf is not working on any of them.
After the execution of the code, many figures are open. So without clicking on a specified figure, findall(gcf,'type','ColorBar') does not return anything ! but afte I click on a given figure with a colorbar, the following command
set(findall(gcf,'type','ColorBar'),'TickLabelInterpreter', 'Latex')
would not make the label of the colorbar of latex format. But the ticks are in Latex.
Adam Danz
Adam Danz 2020 年 10 月 12 日
"...gcf is not working on any of [the figures]"
Not sure what that means. gcf() merely returns the handle of whatever figure is current or creates a new figure if none exist. If you want to operate on a specific figure without manually selecting it, you can either use gcf() immediately after opening the specific figure or you can programmatically selecting it by matching its figure name, tag, or some other property or set of properties that makes the figure unique.
"findall(gcf,'type','ColorBar') does not return anything"
As long as you're using Matlab's builtin gcf(), and the current figure contains a colorbar, it should return the colorbar handle. If the current figure does not contain a colorbar, it should return an empty handle,
figure(); %create figure, no colorbar
findall(gcf,'type','ColorBar')
% ans =
% 0×0 empty GraphicsPlaceholder array.
"... after I click on a given figure with a colorbar, the following command ... would not make the label of the colorbar of latex format. But the ticks are in Latex."
Yes, that command only affects the colorbar axes/ticks. Axis labels and titles do not have the TickLabelInterpreter property. I'm not sure why searching for findall(gcf,'-property','interpreter') doesn't identify the ylabel and title of a colorbar. Here's what you can do,
% Find handle to colorbar
cb = findall(gcf,'Type','Colorbar');
% set interpreter of label and|or title
cb.Label.Interpreter = 'latex';
Walter Roberson
Walter Roberson 2020 年 10 月 13 日
I just experimented with R2019a, and had no problem with
set(findall(gcf,'type','ColorBar'),'TickLabelInterpreter', 'Latex')
For the case of multiple figures, then
set(findall(groot,'type','ColorBar'),'TickLabelInterpreter', 'Latex')
Mary
Mary 2020 年 10 月 13 日
Thanks to both of you.
The only command which works for me for the colorbar label of a current figure is the one mentionned by Adam:
% Find handle to colorbar
cb = findall(gcf,'Type','Colorbar');
% set interpreter of label and|or title
cb.Label.Interpreter = 'latex';
The ones mentionned by Walter are changing only the tick interpreter of colorbars and unfortunately, not their label. That is the case for me. I thank you Walter for sharing that. Because it is useful to have a command doing the job for all open figures. I am sure that will be used by other people reading the post.
Adam Danz
Adam Danz 2020 年 10 月 13 日
Yeah, I don't know why findall(gcf,'-property','interpreter') doesn't detect the colorbar label handles.
Walter Roberson
Walter Roberson 2020 年 10 月 13 日
findall() looks like it perhaps only chases through Children, and objects such as Rulers and tick label text objects are not entered under Children.
Adam Danz
Adam Danz 2020 年 10 月 13 日
編集済み: Adam Danz 2020 年 10 月 13 日
It's gotta be something like that. What's odd is that when a ylabel is assigned to a colorbar, the label's parent is the colorbar but it does not show up as a child of the colorbar nor does findall return the ylabel when searching the colorbar object. Note that by default HandleVisibility for the ylabel is 'on'.
clf()
cb = colorbar();
yl = ylabel(cb, 'cb label');
yl.Parent
% ans =
% ColorBar (cb label) with properties:
%
% Location: 'eastoutside'
% Limits: [0 1]
% FontSize: 9
% Position: [0.83048 0.11048 0.038095 0.81524]
% Units: 'normalized'
%
% Show all properties
cb.Children
% ans =
% 0×0 empty GraphicsPlaceholder array.
findall(cb,'-property','interpreter')
% ans =
% 0×0 empty GraphicsPlaceholder array.
Walter Roberson
Walter Roberson 2020 年 10 月 13 日
I did notice the same thing.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Object Properties についてさらに検索

タグ

質問済み:

2020 年 10 月 5 日

コメント済み:

2020 年 10 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by