[SciPy-user] plot vertical lines

Angus McMorland amcmorl@gmail....
Mon Jul 13 12:06:33 CDT 2009

2009/7/13 Afi Welbeck <welby555@yahoo.com>:
> Hi,
> Thanks it worked. I realised my error.
> If I may ask, is there a way to put the
> pairs of points that make a vertical line
> into a list and then plot them so you have
> a number of vertical lines without having
> to list them separately?
> Thanks.

You can construct a list of lists (or a 2d numpy array) that will do
this. In array terminology (which is easier to describe) the elements
of the first dimension are the points in each line, and the second
dimension gives multiple lines to plot, like so:

import matplotlib.pyplot as plt
xs = [[1,3],[1,3]]
ys = [[1,2],[4,6]]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(xs, ys)
ax.set_xlim([0, 4])
ax.set_ylim([0, 7])

The corresponding arrays would be created by substituting in:

import numpy as np
xs = np.array([[1,3],[1,3]])
ys = np.array([[1,2],[4,6]])

These are really matplotlib questions, so it would be best to move any
further questions on to the matplotlib list
(matplotlib-users@lists.sourceforge.net), which will make sure they
reach the most relevant audience.

AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh

More information about the SciPy-user mailing list