From: John H. <jdh...@ac...> - 2005-02-11 20:03:33
|
>>>>> "Robert" == Robert Leftwich <ro...@le...> writes: Robert> I wrote: >> How can I decrease the size of the actual graph so that the >> labels are displayed? >> Robert> The answer seems to be to use the following after drawing Robert> the graph: ax = gca() ax.set_position([0.2,0.2,0.6,0.6]) Robert> This was taken from the mailing list discussion on Robert> GnuPlot's 'set size ratio' command - Robert> (http://sourceforge.net/mailarchive/forum.php?thread_id=5562487&forum_id=33405) Robert> Is this the correct approach? Yep, that's it -- this is also discussed here http://matplotlib.sf.net/faq.html#TEXTOVERLAP , which also gives an alternative suggestion. Robert> PS One thing that I am having trouble getting my head Robert> around fully is how best to handle the coding, i.e. I'd Robert> prefer to use the class library approach as I like it's Robert> clean, well structured nature, but a number of techniques, Robert> such as the above, are written/illustrated using the Robert> Pylab/Matlab commands which I find difficult to translate Robert> into the class library code. What is the best approach to Robert> getting up the learning curve? Are there any problems with Robert> mixing the two approaches in the one code base? It's a common complaint, so don't feel along. Have you seen examples/pythonic_matplotlib.py -- there is some header documentation there that offers some pointers. That is an example using the pylab interface in a more OO way. For pure OO w/o the pylab interface at all, there is a new example in CVS which I'll put here #!/usr/bin/env python """ A pure OO (look Ma, no pylab!) example using the agg backend """ from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure fig = Figure() canvas = FigureCanvas(fig) ax = fig.add_subplot(111) ax.plot([1,2,3]) ax.set_title('hi mom') ax.grid(True) ax.set_xlabel('time') ax.set_ylabel('volts') canvas.print_figure('test') My advice, don't be afraid to open up matplotlib/pylab.py to see how the pylab interface forwards its calls to the OO layer. I appreciate that "read the source" is not very comforting, but that, the examples I pointed you too above, the all-too-short Chapter 7 of the user's guide, the examples/embedding* demos, and the mailing lists, which are regularly read by many developers, are what we've got right now. I always encourage new users starting on the path to matplotlib OO API enlightenment to make notes and write a tutorial as you go. It would be a useful addition to the documentation. JDH |