On Wed, Mar 24, 2010 at 1:37 PM, Chris Barker <[email protected]> wrote:
> Michael Droettboom wrote:
>> What is the advantage of JSON (is this specific case) over Python source
>> code? matplotlib is designed around it and it's more flexible. Unless
>> you're planning on automatically manipulating the JSON, I don't see why
>> you wouldn't just use Python source.
>
> Indeed. There have been a few threads about this topic, and I think the
> consensus is that the way to auto-generate figures is with python.
>
> I don't think that there is any technical reason that one couldn't
> create a serialized version of an MPL figure in XML, or JSON, (or, for
> that matter, a python data structure), but it would be a fair bit of
> effort to write the code, and I don't think you'd get any real advantage
> over just using scripts -- you need a python script to create a figure
> in the first place, why not serialize that?
Chris,
To answer your question, because I can't think of a way to build a
web-based user interface to let users make incremental changes to the
plot produced by that script. Or some other plot that was generated
using a different script.
ISTM if I have a defined serialization structure (whether it be in
XML, JSON, or a python data structure) I can more easily build a
web-based user interface for manipulating that structure. Below is an
example figure structured as a python dict and a rendering function.
Not sure if this clarifies what I am trying to do ...
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plot = {
'metadata': {
'description': 'This is a sample plot representation',
'matplotlib_version': '0.99.0',
'author': 'RMK',
'last_updated': [2010, 3, 24, 13, 25, 0],
'type': 'lineplot'
},
'figure':
{'methods':
[
['set_size_inches', [10,4], {} ]
]
},
'axes':
{
121:
{'datasets':[
{
'data': [ [1,2,3], [4,5,6] ],
'options': {'linewidth':4, 'label': 'Source 1'},
},
{
'data': [ [1,2,3], [12,13,14] ],
'options': {'linewidth':4, 'label': 'Source 2',
'marker':'*', 'visible': True},
}
],
'methods': [
['set_xlabel', ["Testing ..."], {} ],
['legend', [], {} ]
]
},
122:
{ 'datasets': [
{
'data': [ [1,2,3], [7,8,9] ],
'options':{'linewidth':4, 'label': 'Source 3'},
}
],
'methods': [
['set_xlabel', ["Label ..."], {} ],
['legend', [], {} ]
]
}
}
}
def generate(plot,figname):
fig = plt.figure()
methods = plot['figure']['methods']
for method, args, kwds in methods:
getattr(fig, method)(*args, **kwds)
for axes in plot['axes']:
ax = plt.subplot(axes)
datasets = plot['axes'][axes]['datasets']
for dataset in datasets:
plt.plot(*(dataset['data']), **(dataset['options']))
for method, args, kwds in plot['axes'][axes]['methods']:
getattr(ax, method)(*args, **kwds)
plt.savefig(figname)
if __name__ == '__main__':
generate(plot, 'junk.png')
Rich
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users