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
2020년 10월 5일
h = findall(0, '-property', 'TickLabelInterpreter');
set(h, 'TickLabelInterpreter', 'Latex')
댓글 수: 19
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 ?
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');
set(findobj('type', 'legend'), 'Interpreter', 'latex', 'Box', 'off')
Thanks Walter. That works.
Now, it only remains to have access to the colorbar's legend and make latex the interpreter.
Given Walter's example of finding legend handles, how do you think you could find a colorbar handle?
Based on his comment, I tried the following
set(findall(gcf,'type','ColorBar'),'Interpreter', 'Latex')
but it did not work
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.
set(findall(gcf,'type','ColorBar'),'TickLabelInterpreter', 'Latex')
Thanks Walter. But I don't know why that is not working for me.
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)?
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.
"...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';
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')
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.
Yeah, I don't know why findall(gcf,'-property','interpreter') doesn't detect the colorbar label handles.
findall() looks like it perhaps only chases through Children, and objects such as Rulers and tick label text objects are not entered under Children.
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.
I did notice the same thing.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)
