<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Michael Jay Lissner</title><link href="https://michaeljaylissner.com/" rel="alternate"></link><link href="https://michaeljaylissner.com/feeds/tag/pycairo" rel="self"></link><id>https://michaeljaylissner.com/</id><updated>2009-01-19T16:25:32-08:00</updated><entry><title>Working with matplotlib and pycairo</title><link href="https://michaeljaylissner.com/posts/2009/01/19/working-with-matplotlib-and-pycairo/" rel="alternate"></link><updated>2009-01-19T16:25:32-08:00</updated><author><name>Mike Lissner</name></author><id>tag:michaeljaylissner.com,2009-01-19:posts/2009/01/19/working-with-matplotlib-and-pycairo/</id><summary type="html">&lt;p&gt;I spent a good part of my winter break working on learning &lt;a href="http://python.org"&gt;Python&lt;/a&gt; and 
using it for projects. One project was the &lt;a href="https://michaeljaylissner.com/posts/2008/12/21/yelp-scraper/"&gt;Yelp scraper&lt;/a&gt; that I posted 
about previously, and another was a report for my old&amp;nbsp;work. &lt;/p&gt;
&lt;p&gt;The report is a statistical analysis of the development of about 2,000 children 
aged three and four. For those interested, I&amp;#8217;ll try to post it here once 
the final version is ready to go. In the past when making the report, 
I had been frustrated because there was no easy way to script the creation 
of the 30 or so charts that need to be made. Excel had been our data 
analysis tool, and as such, we were stuck with either using &lt;span class="caps"&gt;VBA&lt;/span&gt; to create 
charts, or to do it by hand. Since nobody knew &lt;span class="caps"&gt;VBA&lt;/span&gt;, we always just buckled 
down and did the work by&amp;nbsp;hand.&lt;/p&gt;
&lt;p&gt;This time around, I discovered the &lt;a href="http://matplotlib.sourceforge.net/"&gt;&lt;code&gt;matplotlib&lt;/code&gt; Python library&lt;/a&gt;, 
and used that to create the charts. It was an pretty rough experience all 
in all. While simple graphs can be created in about five lines of code, 
creating complicated ones took a good amount of work. For example, 
to change the tick markers on a graph requires that you create tick 
objects, and then manipulate them each individually in a for loop. Granted,
I couldn&amp;#8217;t customize them at all in Excel, but figuring out that kind of 
change was a pain&amp;nbsp;indeed. &lt;/p&gt;
&lt;p&gt;The report itself required about 1,000 lines of code, 
and each chart required about 100-200 lines. For custom charts, 
I didn&amp;#8217;t find the library that useful, however towards the end of the 
report there are 30 charts, all of which are identical, 
except for the data. For these charts, I was able to make a for loop that 
created them all in about 20 minutes, whereas previously these took me a 
few hours to make by&amp;nbsp;hand. &lt;/p&gt;
&lt;p&gt;Another library I spent some time learning was &lt;a href="http://www.cairographics.org/pycairo/"&gt;&lt;code&gt;pycairo&lt;/code&gt;&lt;/a&gt;, 
which allows pixel by pixel editing of pictures. I had planned to use it to
do any editing to the charts that I was unable to accomplish with the 
&lt;code&gt;matplotlib&lt;/code&gt; library, but in the end, it was unnecessary. I have another 
project coming up though that will use the &lt;code&gt;pycairo&lt;/code&gt; library, 
so look for that&amp;nbsp;soon.&lt;/p&gt;</summary><category term="Python"></category><category term="programming"></category><category term="matplotlib"></category><category term="pycairo"></category><category term="project"></category></entry></feed>