You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
A function to set common properties for all open figures
20 views (last 30 days)
Show older comments
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
Accepted Answer
Adam Danz
on 5 Oct 2020
h = findall(0, '-property', 'TickLabelInterpreter');
set(h, 'TickLabelInterpreter', 'Latex')
19 Comments
Mary
on 5 Oct 2020
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
on 5 Oct 2020
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');
Mary
on 5 Oct 2020
Now, it only remains to have access to the colorbar's legend and make latex the interpreter.
Adam Danz
on 5 Oct 2020
Given Walter's example of finding legend handles, how do you think you could find a colorbar handle?
Mary
on 5 Oct 2020
Based on his comment, I tried the following
set(findall(gcf,'type','ColorBar'),'Interpreter', 'Latex')
but it did not work
Adam Danz
on 5 Oct 2020
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.
Adam Danz
on 7 Oct 2020
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
on 12 Oct 2020
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
on 12 Oct 2020
"...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
on 13 Oct 2020
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
on 13 Oct 2020
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
on 13 Oct 2020
Yeah, I don't know why findall(gcf,'-property','interpreter') doesn't detect the colorbar label handles.
Walter Roberson
on 13 Oct 2020
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
on 13 Oct 2020
Edited: Adam Danz
on 13 Oct 2020
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.
More Answers (0)
See Also
Categories
Find more on Colorbar in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)