|
From: matthew a. <ma...@ca...> - 2004-01-05 01:44:09
|
Hi
I'm writing a small script to plot my data, and I'd like to use a command
line option to allow the same plot to be either displayed with GTK or
output to postscript.
This means I have to switch matplotlib backends within the script.
Now by the time I know what option the user has chosen, I'm in a function:
def plotThings(options):
matplotlib.use(options.plotbackend)
from matplotlib.matlab import *
plot(...)
...
and python complains
SyntaxWarning: import * only allowed at module level
It still works, but I think I'm on thin ice. And it doesn't work if I do:
def main():
# ... parse options ...
matplotlib.use(options.plotbackend)
from matplotlib.matlab import *
plotThings(options)
SyntaxWarning: import * only allowed at module level
NameError: global name 'plot' is not defined
The matplotlib docs say you need to specify the backend before importing
matplotlib.matlab. But this seems a bit restrictive: what if I want to
display a plot on screen, and then output the same plot to postscript and
print it? Normally imports are done only once at the top of a file, but
I'd like to be able to switch backends anywhere.
What are your thoughts on this issue?
I've been using matplotlib for a while. It's the best python plotting tool
I reckon. Thanks for contributing to free software.
Cheers and thanks,
Matthew.
|