matplotlib

How to fix ImportError in matplotlib

I compiled matplotlib on a mac running snow leopard only to find that when I import matplotlib.pyplot I get the following error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/pyplot.py", line 6, in <module> fro...

Matplotlib savefig image trim

The following sample code will produce a basic line plot with no axis and save it as an SVG file: import matplotlib.pyplot as plt plt.axis('off') plt.plot([1,3,1,2,3]) plt.plot([3,1,1,2,1]) plt.savefig("out.svg", transparent = True) Question 1) How do I set the resolution / dimensions off the image? Qestiion 2) There is padding on al...

Matplotlib: one line, plotted against two related x axes in different units?

I have one y variable, which I am trying to plot against two related x axes, on the top and bottom of the figure (e.g. y="number of things in cube", x1="side length of cube", x2="volume of cube"). I have y, x1, x2 in numpy arrays. The relationship between my x1 and x2 is one-to-one and monotonic, but not simple, and they increase in diff...

python/matplotlib - parasite twin axis scaling

Trying to plot a spectrum, ie, velocity versus intensity, with lower x axis = velocity, on the upper twin axis = frequency The relationship between them (doppler formula) is f = (1-v/c)*f_0 where f is the resulting frequency, v the velocity, c the speed of light, and f_0 the frequency at v=0, ie. the v_lsr. I have tried to solve ...

cannot change font to Helvetica in Matplotlib in Python on Mac OS X 10.6

I am trying to change the matplotlib font to helvetica, which I'd like to use in a PDF plot. I try the following: import matplotlib matplotlib.use('PDF') import matplotlib.pylab as plt from matplotlib import rc plt.rcParams['ps.useafm'] = True rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']}) plt.rcParams['pdf.fonttype'] ...

Matplotlib window 'Not Responding'/hangs/stops updating when out-of-focus

Hello All, Running: Windows Vista Python 2.6 Matplotlib 0.99.3 The following script using draw() in matplotlib seems to work all right until almost anything momentarily interferes with the plot window. import pylab as p import time try: p.ion() fig = p.figure() subplt = fig.add_subplot(111, aspect='equal') subplt.s...

Scale legend box border, dashed and dotted lines when the figure size is changed with matplotlib

I'm trying to use matplotlib to prepare some figures for publication. In order to make the font sizes match the text of the manuscript I'm trying to create the figure in the final size to begin with, so that I avoid scaling the figure when inserting it into the manuscript. The problem I'm having is that as the figure is then pretty smal...

matplotlib. How do I switch between subplots, rather than replotting them from scratch?

I create a figure and fill it with a couple of subplots. As new data arrives, I'd like to draw it on a given subplot. How do I switch between subplots so that I don't have to create new subplot objects each time? Example: from matplotlib.pyplot import figure, figure() subplot(2,1,1) subplot(2,1,2) # now go back and plot something o...

Creating square subplots (of equal height and width) in matplotlib

When I run this code from pylab import * figure() ax1 = subplot(121) plot([1, 2, 3], [1, 2, 3]) subplot(122, sharex=ax1, sharey=ax1) plot([1, 2, 3], [1, 2, 3]) draw() show() I get two subplots which are "squished" in the X-dimension. How do I get these subplots such that the height of the Y-axis equals the width of the X-axis, for bo...

additional python installed upon installing matplotlib with macports

I am having trouble installing matplotlib on mac os 10.6, so I used macports and installed all dependencies it needed, which is great, but on top of it a new python version. Now I have two python versions and that bothers me. The matplotlib is working fine on the macport python, and the rest of my stuff is with the default python. What ...

How to plot empirical cdf in matplotlib in Python?

How can I plot the empirical CDF of an array of numbers in matplotlib in Python? I'm looking for the cdf analog of pylab's "hist" function. One thing I can think of is: from scipy.stats import cumfreq a = array([...]) # my array of numbers num_bins = 20 b = cumfreq(a, num_bins) plt.plot(b) Is that correct though? Is there an easie...

Interactive Stacked Bar Chart using MatplotLib python

Dear All, I need to create a stacked bar chart using matplotlib. Each bar should be a stack of the parameters I am measuring. However, I want it to be interactive or dynamic so as when I click on one of the parameters (A,B,C) for example in the legend, it should make that parameter at the bottom of the stack so as we could have a better...

matplotlib annotate multiple data sets

If I feed several x/y sets to matplotlib.pyplot.plot, how does annotate decide how to correlate the xy value to one of the sets? Is there an assumption that all the sets are scaled the same way? plt.plot(clist, plist, 'g', clist, rlist, 'r', clist, flist, 'b') plt.annotate("%d chars F=%f" % (threshold_c, threshold_f), xy=(threshold_c,...

Matplotlib autoscale

I need to get a plot that fits the data automatically using matplotlib. This is the code I was given: import matplotlib.pyplot as plt from matplotlib.collections import LineCollection .... lines = LineCollection(mpl.line_holder, colors=mpl.colorholder , linestyle='solid') plt.axes().add_collection(lines) plt.axes().set_aspect('equal', '...

Matplotlib: move graph to the right

I have two graphs with in one image, each with 5 points. Their value on the X axis is not important, all that I require is that they're all equally distributed on it. import matplotlib.pyplot as plt data = [43,51,44,73,60] data2 = [34,25,42,53,61] fig = plt.figure(1) ax = fig.add_subplot(111) ax.plot(data, '-o', color='#000000', lw=...

Matplotlib: plot multiple graphs using same figure, without them overlapping

I have a class which I use to plot things then save them to a file. Here's a simplified version of it: import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt class Test(): def __init__(self, x, y, filename): fig = plt.figure(1) ax = fig.add_subplot(111) ax.plot(x, y, 'D', color='red') ...

Non-interactive ploting with matplotlib on Mac OS X

I am using scipy-cluster in my application. It provides a function to plot a dendrogram of the hierarchical cluster tree. Looking at the source I find that it eventually plots the dendrogram by calling draw_if_interactive. As one would expect, this works fine in an interactive session, but when I run the script non-interactively, a windo...

How do I force matplotlib to write out the full form of the x-axis label, avoiding scientific notation?

Hello, I've created a simple hexbin plot with matplotlib.pyplot. I haven't changed any default settings. My x-axis information ranges from 2003 to 2009, while the y values range from 15 to 35. Rather than writing out 2003, 2004, etc., matplotlib collapses it into 0, 1, 2, ... + 2.003e+03. Is there a simple way to force matplotlib to...

Invert colormap in matplotlib

I would like to know how to simply reverse the color order of a given colormap in order to use it with plot_surface. ...

How to switch backends in matplotlib / Python

Hi, I am struggling with the following issue. I need to generate reports that consists of a collection of charts. All these charts, except one, are made using Matplotlib default backend (TkAgg). One chart needs to be made using the Cairo backend, the reason is that I am plotting an igraph graph and that can only be plotted using Cairo. ...