I\'ve been generating bar charts that look like this:
Notice that the
like user1127062 suggests, it might be that your code is just fine.
If you don't need the plot to be interactive, save it as an svg
If you run:
data = numpy.random.randn(10000)
pylab.hist(data,300)
pylab.savefig(fileName+'.svg',format='svg')
you'll see the pixel aliasing (in the bar widths) in the figure window, but it's gone in the svg file.
The "cairo" backend seems to do the best job of saving png files, if svg's aren't compatible with what you're doing. They look as good as a screenshot of the svg.
You can switch the backend by running.
import matplotlib
# you have to change the backend before importing pylab
matplotlib.use('cairo')
import pylab
raw "cairo" doesn't support show()
, so you can't use it in interactive mode, or to show a plot directly from a program.
The "GTKCairo" backend has the best of both worlds but isn't enabled in the default installation (at least not in the one I got with sudo apt-get install matplotlib
)
If you're using Ubuntu I think all you need to do to get it working is to install gtk, and recompile matplotlib:
sudo apt-get install git-core python-gtk2-dev
git clone git://github.com/matplotlib/matplotlib.git
cd matplotlib
sudo python setup.py install
You can check which backend is active with:
matplotlib.get_backend()
You can automatically load your favorite backend by hunting down your matplotlibrc
file, I found mine in:
/usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/matplotlibrc