using plot(single_object)

I was wondering if there is an easy way to
combine two vectors (x and y) into a single object to be ploted with
the plot() method in matplotlib.

Untill now, I did something like:

import matplotlib.pyplot as plt

x = np.nplinspace(0,5,1000)

y = np.ones_like(x)

plt.plot(x,y) # need an object here

plt.show()

But I would like to use plt.plot(my_object, ‘r’).

I tried to combine x and y in lists of lists, NumPy matrices, with zip,
etc…but it only plots a collection of plots.

Thanks a lot in advance.

I was wondering if there is an easy way to
combine two vectors (x and y) into a single object to be ploted with
the plot() method in matplotlib.

Untill now, I did something like:

import matplotlib.pyplot as plt

x = np.nplinspace(0,5,1000)

y = np.ones_like(x)

plt.plot(x,y) # need an object here

plt.show()

But I would like to use plt.plot(my_object, ‘r’).

I tried to combine x and y in lists of lists, NumPy matrices, with zip,
etc…but it only plots a collection of plots.

Thanks a lot in advance.

You could take advantage of python’s expansion of positional arguments like so:

import matplotlib.pyplot as plt
import numpy as np
foo = [np.arange(30), np.random.random((30,))]

plt.plot(*foo)
[<matplotlib.lines.Line2D object at 0x97aef6c>]
plt.show()

The behavior that you describe (plotting many lines) is documented and expected behavior with a list.

Ben Root

···

On Sun, Dec 12, 2010 at 11:51 AM, Jose Guzman <sjm.guzman@…1762…82…> wrote: