Re: [Matplotlib-users] error: Gtk* backend requires pygtk to be installed

2010-06-25 Thread Mike Anderson
Hi,

 Went looking on examples page and found there was a file name demo_image.py
 http://matplotlib.sourceforge.net/examples/axes_grid/demo_image.html

 However for whatever reason the source code was not downloadable (404
 error), so I copied it off the html page.

I'm not sure why the matplotlib examples page would contain weird
dependencies like that, rather than just having simpler examples.

As for 'pip', it is a replacement for 'easy_install', both of which
find and install python packages.  pip is meant to improve on
easy_install, with new features and more stability.


And I think you figured out my exact problem:

 I'd be questioning your configuration of matplotlib, there should be a rc
 file somewhere, maybe you (or your distro) have set the backend to gtk by
 default?

Yep, unfortunately in ~/.matplotlib/matplotlibrc
this line was set to
backend  : GTKAgg

So I fixed that.  The other solution I found is to have at the top of
the plotting script the matplotlib.use() statement so that it uses
something else for a backend:

import matplotlib   # Do this before importing pylab or pyplot
#matplotlib.use('Agg')   # Anti-Grain Geometry  (raster images)
matplotlib.use('PDF')
import matplotlib.pyplot as plt

Thanks!
Mike

--
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] axis on top for barh plot

2009-11-29 Thread Mike Anderson
Hi!

 How can I put the bottom axis on top (or on top AND on bottom) for a barh 
 plot?

 It's somewhat counter-intuitive, but it can be done.
 You have to create some twin axes with the twiny option,
 then make the plot on the twin axes so it will use the
 top axis. The bottom axis still have to be adjusted manually
 to make it match the top one and remove the labels.
 
 See this example:
 

Thanks for your example.  With your help I was able to finally create this with 
matplotlib,
  http://www.hep.wisc.edu/cms/comp/cmsprod/diskUserUsage.png
and this is my final script,
  http://www.hep.wisc.edu/cms/comp/cmsprod/plotDiskUse.py



One thing that surprised me was to shrink the font for the names required 
changing ax1 even though the barh plot is on ax2.  See these lines:

--
  ax2.barh(pos, listUse, color=listColors, height=1.0, align='center')
 ...
  for tick in ax1.yaxis.get_major_ticks():
tick.label1.set_fontsize(8)
--

Surprising.
Mike

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] axis on top for barh plot

2009-11-27 Thread Mike Anderson
Hi,

How can I put the bottom axis on top (or on top AND on bottom) for a barh plot?

I'm trying to mimic this, made with gnuplot:

  http://www.hep.wisc.edu/cms/comp/cmsprod/dCacheUserUsage.png

within matplotlib, and I've come close,

  http://www.hep.wisc.edu/cms/comp/cmsprod/diskUserUsage.png


Also, is it possible to just have grid lines in one direction (say, vertical), 
I don't think the horizontal grid is necessary.

Thanks for any help,
Mike



PS: Anyone who is interested, my script for making that is here,
  http://www.hep.wisc.edu/cms/comp/cmsprod/plotDiskUse.py

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] matplotlib slow compared to gnuplot?

2009-11-11 Thread Mike Anderson
Hi all,

Previously I was a user of gnuplot but have been giving matplotlib a  
try.  One thing I've run in to right away is that matplotlib appears  
to be significantly slower.

A script to produce a dozen plots was taking me ~1 second with  
gnuplot, and now takes me ~18 seconds with matplotlib.

I'm curious if anyone knows how to speed things up.  To figure out  
what is taking most of the time, I've used cProfile and pstats and  
below is the top 15 functions taking the most time.
   (note: plotStackedJobsVsTime is my function that uses matplotlib.)


Wed Nov 11 08:43:52 2009fooprof

  3069840 function calls (3009711 primitive calls) in 17.658  
CPU seconds

Ordered by: cumulative time
List reduced from 873 to 15 due to restriction 15

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
 10.0000.000   17.658   17.658 string:1(module)
 10.0070.007   17.658   17.658 /cms/cmsprod/bin/ 
prodJobMonitorPlots_matplotlib.py:151(main)
130.6200.048   17.6471.357 /cms/cmsprod/bin/ 
prodJobMonitorPlots_matplotlib.py:54(plotStackedJobsVsTime)
130.0000.000   10.0870.776 /afs/hep.wisc.edu/cms/ 
sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ 
matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/figure.py:959 
(savefig)
130.0280.002   10.0860.776 /afs/hep.wisc.edu/cms/ 
sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ 
matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/ 
backend_bases.py:1372(print_figure)
130.0280.0029.8470.757 /afs/hep.wisc.edu/cms/ 
sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ 
matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/backends/ 
backend_agg.py:357(print_png)
130.0000.0009.2430.711 /afs/hep.wisc.edu/cms/ 
sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ 
matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/backends/ 
backend_agg.py:307(draw)
   3206/130.0400.0009.2220.709 /afs/hep.wisc.edu/cms/ 
sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ 
matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/artist.py:44 
(draw_wrapper)
130.0010.0009.2220.709 /afs/hep.wisc.edu/cms/ 
sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ 
matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/figure.py:729 
(draw)
130.0050.0009.2000.708 /afs/hep.wisc.edu/cms/ 
sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ 
matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/axes.py:1632 
(draw)
260.0290.0015.6240.216 /afs/hep.wisc.edu/cms/ 
sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ 
matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/axis.py:727 
(draw)
1533/13250.0780.0003.6630.003 /afs/hep.wisc.edu/cms/sw/ 
python/x86_64/2.5.4/lib/python2.5/site-packages/matplotlib-0.99.1.1_r0- 
py2.5-linux-x86_64.egg/matplotlib/axis.py:61(__init__)
   8110.0350.0003.0570.004 /afs/hep.wisc.edu/cms/ 
sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ 
matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/axis.py:181 
(draw)
130.0010.0002.6190.201 /afs/hep.wisc.edu/cms/ 
sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ 
matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/legend.py:342 
(draw)
  1065/9610.0120.0002.5430.003 /afs/hep.wisc.edu/cms/ 
sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ 
matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/axis.py:1207 
(_get_tick)



My script, for the curious, is at
   
http://www.hep.wisc.edu/cms/comp/routerqMonitor/prodJobMonitorPlots_matplotlib.py
and produces these plots:
   http://www.hep.wisc.edu/cms/comp/routerqMonitor/index.html


Any hints at what I can do to speed up my script?  Or is it out of my  
hands because it's all in matplotlib?

Thanks for any help,
Mike

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] parsing tab separated files into dictionaries - alternative to genfromtxt?

2009-11-11 Thread Mike Anderson
 ideally what i would like is to be able to traverse each line of the
 parsed file, and then refer to each of its fields by header name, so
 that if the column order in the file changes my program will be
 unaffected:



What you want is a DictReader.

For a quick example of me using that,
--
aReader = csv.DictReader(open(inputFilename, 'r'), delimiter='\t')

yValues = {}  # Will be a dictionary of lists  (these are lists of y- 
values)
xValues = []  # List of x values (timestamps)

for row in aReader:
xValues.append(datetime.datetime(*(time.strptime(row 
['TimeStamp'],timeStampFormat)[0:6])))
for field in sorted(row,reverse=True): # Read from last  
to first in field list
if field=='TimeStamp': continue  # Column of x-data
if not field in yValues.keys():
yValues[field] = [nt(row[field])]   # Start list of 
the values  
in this column
else:
yValues[field].append(int(row[field])) # Add to list of 
values in  
this column
--


Mike

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Plotting with times - axis labels and eliding times

2009-10-24 Thread Mike Anderson
Hi,

* The time ranges are large (one-second samples over a period of
  several days) and I find the x axis label formats are often
  inappropriate to the scale.  How to I control the format of
  the x axis labels?


I only started using matplolib a few days ago, but I think I know how  
to do what you want:


import matplotlib.dates as mdates  # To read timestamps
...
xAxisTimeFormat   = '%a\n%H:%M' # Format of time stamps on x-axis
hourLocator   = mdates.HourLocator(interval=5)# Every 5 hours
minuteLocator = mdates.MinuteLocator(interval=30) # Every half hour
   ...
ax.xaxis.set_major_locator(hourLocator)# Set major tick marks
ax.xaxis.set_minor_locator(minuteLocator) # Set minor tick marks
ax.xaxis.set_major_formatter(mdates.DateFormatter(xAxisTimeFormat))  #  
Format x-axis labels


I have a full example of plots that have a point every minute over the  
course of days:
   http://www.hep.wisc.edu/cms/comp/routerqMonitor/index.html
with a link to the full python script at the bottom.

Mike

--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] fill_between, legends, and label parameter

2009-10-22 Thread Mike Anderson
 If you want to have a legend for PolyCollection, you may use a proxy  
 artist.

 http://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist


Thanks for the link!  Although, it seems that legend does not support  
PolyCollection at all:

   Remember that some pyplot commands return artist not supported by  
legend, e.g., fill_between() returns PolyCollection that is not  
supported.

so that even trying to use a proxy artist results in an error (shown  
at bottom), with the code here:
--
listOfThingsPlotted = []
listOfLegendLabels  = []
for column in sorted(yValues):
 temp = ax.fill_between(xValues, yValues[column], label=column)
 listOfThingsPlotted.append(temp)
 listOfLegendLabels.append(column)

 legend = plt.legend 
(listOfThingsPlotted,listOfLegendLabels,bbox_to_anchor=(1.25, 1),  
shadow=True, fancybox=True)
--



Error:
--
Traceback (most recent call last):
   File /cms/cmsprod/bin/prodJobMonitorPlots_matplotlib.py, line  
117, in module
 plotStackedJobsVsTime(inputFile, outputFile, outputTitle)
   File /cms/cmsprod/bin/prodJobMonitorPlots_matplotlib.py, line 93,  
in plotStackedJobsVsTime
 legend = plt.legend 
(listOfThingsPlotted,listOfLegendLabels,bbox_to_anchor=(1.25, 1),  
shadow=True, fancybox=True) # Make legend
   File /afs/hep.wisc.edu/cms/sw/python/x86/2.5.4/lib/python2.5/site- 
packages/matplotlib-0.99.1.1_r0-py2.5-linux-i686.egg/matplotlib/ 
pyplot.py, line 2437, in legend
 ret =  gca().legend(*args, **kwargs)
   File /afs/hep.wisc.edu/cms/sw/python/x86/2.5.4/lib/python2.5/site- 
packages/matplotlib-0.99.1.1_r0-py2.5-linux-i686.egg/matplotlib/ 
axes.py, line 4044, in legend
 self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
   File /afs/hep.wisc.edu/cms/sw/python/x86/2.5.4/lib/python2.5/site- 
packages/matplotlib-0.99.1.1_r0-py2.5-linux-i686.egg/matplotlib/ 
legend.py, line 304, in __init__
 self._init_legend_box(handles, labels)
   File /afs/hep.wisc.edu/cms/sw/python/x86/2.5.4/lib/python2.5/site- 
packages/matplotlib-0.99.1.1_r0-py2.5-linux-i686.egg/matplotlib/ 
legend.py, line 582, in _init_legend_box
 handlebox.add_artist(handle)
   File /afs/hep.wisc.edu/cms/sw/python/x86/2.5.4/lib/python2.5/site- 
packages/matplotlib-0.99.1.1_r0-py2.5-linux-i686.egg/matplotlib/ 
offsetbox.py, line 475, in add_artist
 a.set_transform(self.get_transform())
AttributeError: 'NoneType' object has no attribute 'set_transform'

--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] fill_between, legends, and label parameter

2009-10-21 Thread Mike Anderson
Hi,

I have a piece of code that creates a plot without warning when using  
just fill(), but gives a warning when using fill_between() because  
that function doesn't seem to actually do register values passed to it  
by the label parameter.

The warning happens when I try to make a legend after using  
fill_between():
  /cms/sw/python/2.5/lib/python2.5/site-packages/ 
matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/axes.py:4014:  
UserWarning: No labeled objects found. Use label='...' kwarg on  
individual plots.
   warnings.warn(No labeled objects found. 

In essence this code works fine when I use fill() rather than  
fill_between():

for column in sorted(yValues):
ax.fill_between(xValues, yValues[column], label=column)

legend = plt.legend(bbox_to_anchor=(1.3, 1), shadow=True, fancybox=True)


That is, the legend finds the labels when I use fill(), but not when I  
use fill_between().

Why is that?
Mike

--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users