5

Here is a simple matlab script to read a csv file, and generate a plot (with which I can zoom in with the mouse as I desire). I would like to see an example of how this is done in python and mathplotlib.

data = csvread('foo.csv');    % read csv data into vector 'data'
figure;                       % create figure
plot (data, 'b');             % plot the data in blue

In general, the examples in mathplotlib tutorials I've seen will create a static graph, but it's not interactively "zoomable". Would any python expert care to share an equivalent?

Thanks

1
  • What system are you on that the default backend doesn't allow zoomable figures? Commented Dec 8, 2010 at 21:41

2 Answers 2

6
import matplotlib.pyplot as plt
import numpy as np

arr=np.genfromtxt('foo.csv',delimiter=',')
plt.plot(arr[:,0],arr[:,1],'b-')
plt.show()

on this data (foo.csv):

1,2
2,4
3,9

produces

alt text

When you setup the matplotlibrc, one of the key parameters you need to set is the backend. Which backend you choose depends on your OS and installation. For any typical OS there should be a backend that allows you to pan and zoom the plot interactively. (GtkAgg works on Ubuntu). The buttons highlighted in red allow you to pan and zoom, respectively.

Sign up to request clarification or add additional context in comments.

1 Comment

Just what I wanted to get me started! Thanks.
1

Since you're familiar with Matlab, I'd suggest using the pylab interface to matplotlib - it mostly mimics Matlab's plotting. As unutbu says, the zoomability of the plot is determined by the backend you use, a separate issue.

from pylab import *
data = genfromtxt("file.csv")
plot(data, 'b')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.