setting graph defaults

3 次查看(过去 30 天)
easily confused
easily confused 2011-11-15
How do I set the default for all my graphs to be, for example, colorbar visible and interpreter none. I would like to set defaults once, rather than setting the properties in each graph. I've tried all sorts of incantations with DefaultColorbar, but I can't seem to get the right combination.

回答(5 个)

Wayne King
Wayne King 2011-11-15
Search for "Setting Default Property Values" in the MATLAB User's Guide. You can set default figure properties with set(0,...)
set(0,'defaultfiguretoolbar','none')
You can put options in a startup.m file, which is called by matlabrc.m

Jan
Jan 2011-11-17
You can set the DefaultFigureCreateFcn to a function, which sets the Colorbar:
set(0, 'defaultfigurecreatefcn', @myFigureCreateFcn)
But I'd prefer a dedicated function, which wraps the call to FIGURE:
function FigH = myFigure(varargin)
FigH = figure(varargin{:});
colorbar;

easily confused
easily confused 2011-11-16
I understand what you say, but I can't get seem to use it to make the colorbar be on by default.
So, specifically, how can I get the colorbar to be on by default in multiple figures?

Daniel Shub
Daniel Shub 2011-11-17
Setting default behavior so that a "figure" always has a color bar is extremely problematic. Color bars are tied to an axis and not a figure. You might be able to build on Jan's answer and set the DefaultAxesCreateFcn, but this function is going to have to be complicated since the color bar is an axis and therefore is created with the function defined by DefaultAxesCreateFcn. It is unclear if you can determine what the nature of an axis is going to be before it is created so you would probably have to prevent recursive calls to your axes creator function.
Building your own function is also hard since there are so many ways a axis can be created.

easily confused
easily confused 2011-11-18
So the answer is that there is no "default" property with respect to the visibility of the colorbar. I think the colorbar is a graphics object in itself, just like an axes, not tied to an axes. At least it appears that way in the proerties editor. It's parent is the figure. I guess the only way is to create a figurecb function to include creation of a color bar, which is hardly worth the hassle.
  2 个评论
Walter Roberson
Walter Roberson 2011-11-18
colorbar() creates a new axes of the figure, and draws a image within that new axes. The color image is thus tied to an axes of its own, but is not tied to the axes that the colorbar was drawn for.
Daniel Shub
Daniel Shub 2011-11-18
While the colorbar seems like an axes, it is special ...
hfig = figure;
hax = axes;
hcb = colorbar;
ishandle([hfig, hax, hcb])
The issue is that
get([hax, hcb])
gives a weird error about hax and hcb having different classes. This is surprising since they both are of type axes. It is not to surprising that you get an error since hcb has some properties that hax doesn't. It is unclear though how to tell if an object of with a type axes is a colorbar or a regular axis.
You can see that hcb is linked to hax by deleting hax ...
delete(hax)
ishandle([hfig, hax, hcb])

请先登录,再进行评论。

类别

Help CenterFile 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!

Translated by