Using matplotlib / pylab without a DISPLAY

I’ve been having issues with a web system I coded for a while now and couldn’t find a solution that worked to my satisfaction to eliminate the need of a Xvnc running to provide a virtual DISPLAY to run some commands to plot data using pylab.

Finally, today, I found the solution here and I want to share it.

import matplotlib
matplotlib.use('Agg') # Must be before importing matplotlib.pyplot or pylab!
import matplotlib.pyplot as plt

fig = plt.figure()

The solution, here, is the Agg option as the “device” to be used to plot files.

Solution in place, and I can now eliminate the requirement for Xvnc from my code and all the issues that came with it are also automatically gone.

So, here’s the code for Pylab:

import matplotlib
matplotlib.use('Agg') # Must be before importing matplotlib.pyplot or pylab!
import pylab




Ext.extend and Conquer

Today it was a very productive day.

I’ve redesigned several problematic screens of an application into more functional versions, working much faster, providing more information to the end user and – the best thing – with a very consistent appearance on their layout.

ExtJS provides some nice features to standardize its components by extending its standard classes.

The simplest way to do that is like what I show on the code snippet below. It simply provides some default values – that can be easily overriden when the custom component is instantiated – that help with the implementation of sets of components.

var myCustomCombo = new Ext.extend(
        width: 180,
        mode: "local", // I load the data manually from the store.
        triggerAction: "all",
        emptyText: 'Choose an option...',
        autoSelect: false,
      editable: false
Ext.reg('mycustomcombo', myCustomCombo);

I did custom implementations of panels, forms, combo boxes and grids. With that, I make only slightly variations from one case to the other – imagine addresses, where you have several different components from the country up to the zip code for a street, avenue, square, etc.

The new layout also made it possible to eliminate different pages and consolidate all the information on a single page where all records could be browsed, edited, removed or new records could be added to the database.

On the backend – my TurboGears application – my code also shrunk considerably as I didn’t have to make some convoluted queries to get the information. All modules were better decoupled and obtaining the information using AJAX – or better AJAJ since I don’t use XML but use JSON – much easier through a cleaner interface.

Summing up: it was a complete redesign of a whole module in a day. Some hundreds of lines of code eliminated and functionality added to the system.

I hope that tomorrow the day becomes as productive as today.

Quick trick with tables: fixing column width

It is interesting how we never get bored while creating different solutions.

I’m improving the design of an application — and I guess if I am improving it then it was really ugly before… — and needed to add a column that will be larger than the other ones.  Unfortunately, unless you have your data displayed already then all columns will be shown with the same width.

How to solve that?  Using an old trick!

First of all, you define — using colspans, if possible — what is the proportion of the expanded column.

After that, you just specify that such a table should be rendered with a fixed layout in your CSS:

table-layout: fixed;

This will do the trick and render the table the correct way.

Accessibility when developing for the web

There are two concerns when speaking about accessibility: accessibility for disabled people and accessibility for “disabled” browsers.

I’m talking, on this post, about the second category.

So, is this really something that is needed nowadays?  Even the browser on my mobile phone has JavaScript support (though it doesn’t have Flash support) and can run a complex dynamic website without any special change or anything designed to be used on mobile browsers (be them Blackberries, iPhones or other mobile phones).

Some recommendations are to degrade the design when JavaScript is disabled, but the vast majority of users has no idea how to disable JavaScript on their browsers.  If some IT guy from a company does that, should you really be worried with this person accessing your website?  Of course, you are reducing the market for your product, but how many people are excluded?  Are they people that would “buy” some service from the website?  Is this amount of people worth the extra investment that it takes to design a website to degrade and to be pleasant when used fully dynamically?