필터 지우기
필터 지우기

How to change the linewidth in a figure before actually plotting some?

조회 수: 321 (최근 30일)
Ruben
Ruben 2014년 12월 2일
답변: Salvador Castaneda 2021년 10월 23일
I'm working on a matlab function that automatically opens your figure in full screen mode and on a second monitor if present. So far, everything works fine. I already achieved to set the fontsize inside the function, so whitout plotting anything and without making xlabel(..) etc.:
% Fontsize used at the figure
if ~exist('fontsize_manual','var')|| isempty(fontsize_manual)
set(gca,'FontSize',16)
else
set(gca,'Fontsize',fontsize_manual)
end
Now is my question: Can I change in a same way the linewidth of the lines that will by plotted in the figure? So also here, predefining the linewidth inside the function and later on in your script plotting some lines etc. I do prefer this works only for the figure you're working on, so that you can change this 'default' for each figure and save them all with different linewidth and fontsizes if needed.
I tried the line below, but that only changed the linewidth of the axis.
set(gca,'LineWidth',2)
Is there anyone who can help me solving this problem?

채택된 답변

dpb
dpb 2014년 12월 2일
Use the technique of the referenced page but set the default for the figure in question --
set(gca,'DefaultLineLineWidth',2)
NB: the default properties are named in run-on fashion--the name of the object you're setting then the property within that object all preceded with the keyword 'Default'. Here that's
Default:Line:LineWidth
to separate the subsets visually. I think it would've been easier if TMW had used such nomenclature or a structure form instead (and probably the parsing internally would've been simpler as well).
  댓글 수: 9
Ruben
Ruben 2014년 12월 4일
That was indeed the kind of code badness I expected that would give the 'strange' result and I slowly get your explanation. Maybe I have some time left this weekend XD
Do you get the point, what I want to reach with this function? If yes, do you have a smart idea or can you explain short what I maybe can do better, more careful etc?
dpb
dpb 2014년 12월 4일
편집: dpb 2014년 12월 6일
Primarily it looks like everywhere you have a gca you really want something that goes back to your original question and to probably try to set defaults for the just-created figure using
set(figure_handle,'DefaultLineLineWidth',2)
or the desired property/properties on the various other objects besides Line. You'll have to investigate which are and are not inherited from the figure; I don't know that otomh. In the initial query the linewidth property is; I've not investigated for the various font properties from whom they get derived. But, if you can't get to them from the figure then you'll have to have another level at which you create and save the right handles for the axes if you do want to make these dependent on specific figures and axes within those figures rather than global.
It's all doable; you just have to figure out where is the highest point in the object hierarchy you can do so. Try the figure first, obviously, but as soon as you use gca you've gone to an axes level, not figure so you'll have to see if it works substituting gcf first, then switch to the actual figure. If gcf fails because of invalid property then you've got to make the axes object and use (and save) that handle that's tied with the given parent figure.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Robert Cumming
Robert Cumming 2014년 12월 3일
set(0,'DefaultLineLineWidth',2)
This will set the line width for all plots in the current session
The technique your using in @dpb answer only sets the current axes (i.e. gca).
  댓글 수: 1
Ruben
Ruben 2014년 12월 3일
Yeah, but I would have the freedom to choose the linewidth of the plotted object per figure... (A) So the answer @dpb is more suitable for my problem.

댓글을 달려면 로그인하십시오.


Salvador Castaneda
Salvador Castaneda 2021년 10월 23일
This however, was great for mine, thanks

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by