From: Robert L. <ro...@le...> - 2005-02-10 20:14:33
|
I'm plotting a small png for use on a web page and finding that the x and y labels are not being displayed. If I increase the size of the figure using figsize then all is ok. I've tried x/yaxis.set_clip_on(False) and axes([..]) without success. How can I decrease the size of the actual graph so that the labels are displayed? Robert PS If it makes a difference the code I'm using is based on the coloured background region code supplied by John Hunter, i.e. there are 4 subplots, each with a Rectangle and a scatter plot overlaid on the 4 Rectangles. |
From: Robert L. <ro...@le...> - 2005-02-11 19:18:49
|
I wrote: > How can I > decrease the size of the actual graph so that the labels are displayed? > The answer seems to be to use the following after drawing the graph: ax = gca() ax.set_position([0.2,0.2,0.6,0.6]) This was taken from the mailing list discussion on GnuPlot's 'set size ratio' command - (http://sourceforge.net/mailarchive/forum.php?thread_id=5562487&forum_id=33405) Is this the correct approach? Robert PS One thing that I am having trouble getting my head around fully is how best to handle the coding, i.e. I'd prefer to use the class library approach as I like it's clean, well structured nature, but a number of techniques, such as the above, are written/illustrated using the Pylab/Matlab commands which I find difficult to translate into the class library code. What is the best approach to getting up the learning curve? Are there any problems with mixing the two approaches in the one code base? |
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 |
From: Robert L. <ro...@le...> - 2005-02-12 00:15:49
|
John Hunter wrote: > > 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. (Ahhh - a small light bulb is lit!) Ok, I'd seen that but wasn't able to get it to work but now I understand why - when I tried it I'd not made the connection between axes and sub-plots. > For pure OO w/o the pylab interface at > all, there is a new example in CVS which I'll put here Thanks, I'll check it out. > [Snip some good advice] > > 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. No promises - so much to do, so little time :-( I've got to code up the generation of more than 80 different graphs, resulting in over 32k individual instances, which is why I'm looking at matplotlib in preference to gnuplot, hopefully there's less trial and error involved in getting each graph 'just so'. A Wiki might make the tutorial/documentation more achievable/accessible, is there one available? Robert |