|
From: | Ben Abbott |
Subject: | Re: plot templates and options lists for set, plot etc. |
Date: | Sat, 06 Jun 2009 22:32:39 -0400 |
On Jun 6, 2009, at 12:43 PM, Thorsten Meyer wrote:
Hi, Ben Abbott wrote:On Jun 6, 2009, at 11:21 AM, Thorsten Meyer wrote:Hi, at work, I often have to generate the same kind of plots with particular labels, line styles, etc.. I would like to create templates for these plots. For this, I collect plot options in a struct like it is returned by the get function. E.g. style = struct("linewidth", 2, "marker", "x", "markersize", 12); Now, I want to pass these options to the plot function. At the moment, I do it like this:plot(1:5, 5:-1:1, {fieldnames(style)'{:}; struct2cell(style)'{:}} {:});[...]Would you prefer the approach below? props = {"color", [0 1 0], "marker", "s"} h = plot (1:10); set (h, props{:}) If you want to continue to use your structure, you can populate props by ... props = [fieldnames(style), struct2cell(style)]; But that is not really very different from what you're already doing.Yes, I have seen, that the options are collected into a cell array within the plot functions. However, keeping the options in a structure has the advantage, that I can easily access and set the individual options, e.g. to transform one plot template into a new one, etc. Also, how are graphic objects realized internally? Aren't they also structures? It always seemed quite strange to me, that the get() function returns a structure, while all the functions setting handle options take lists of key, value,... as input arguments... Thorsten
Hmmm ... when I first began using set/get, I had assumed that s=get(h) would be reciprocated by set(h,s). Of course there are problems with that example due to some properties being read-only.
However, isn't the functionality below what you're looking for? style = struct("linewidth", 2, "marker", "x", "markersize", 12); h = plot (1:10) set (h, style)I don't see any problem with compatibility. If set() were an m-file, such a change would take me a few minutes, but with c/c++, I won't be much help proposing a patch.
Ben
[Prev in Thread] | Current Thread | [Next in Thread] |