# Role of numpy Method arange in Matplotlib

I'm unsure about the role of numpy method arange in Matplotlib plots. All
Matplotlib examples I have seen call numpy's method arange, and pass the
result as the first arg to Matplotlib's plot method.

But the following works as expected:

--- quote ---
import matplotlib.pyplot as plt
import numpy as np

dom = [1, 3, 4, 5, 7] # Plot domain on x-axis in ascending order of values
ran = [7, -2, 11, 5.8, 0] # Plot range on y-axis in 1-to-1 correspondence
with domain items

fig = plt.figure()
ax = plt.subplot(111)
ax.plot(dom, ran)
plt.grid()
plt.show()
--- end quote ---

I'm not calling numpy.arange(arg) here, but I see the expected plot of 5
co-ordinate points. When should I use numpy.arange(arg) instead of what I
have done above? Something to do with the domain that I want to include in
the plot?

TIA,
Jon

···

--
View this message in context: http://old.nabble.com/Role-of-numpy-Method-arange-in-Matplotlib-tp34223354p34223354.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Nothing is special about arange, it is just a way to generate an array of floating point numbers, much like python’s range(). You can specify start and end values and the stepsize as well, just like for range(), except the stepsize can be a floating point number.

In many examples, you could use python’s range() and get the same results. All that is important is to provide coordinates for each need dimension, from arange(), linspace(), range(), or some other source.

I hope that clears it up.

Ben Root

···

On Friday, July 27, 2012, JonBL wrote:

I’m unsure about the role of numpy method arange in Matplotlib plots. All

Matplotlib examples I have seen call numpy’s method arange, and pass the

result as the first arg to Matplotlib’s plot method.

But the following works as expected:

— quote —

import matplotlib.pyplot as plt

import numpy as np

dom = [1, 3, 4, 5, 7] # Plot domain on x-axis in ascending order of values

ran = [7, -2, 11, 5.8, 0] # Plot range on y-axis in 1-to-1 correspondence

with domain items

fig = plt.figure()

ax = plt.subplot(111)

ax.plot(dom, ran)

plt.grid()

plt.show()

— end quote —

I’m not calling numpy.arange(arg) here, but I see the expected plot of 5

co-ordinate points. When should I use numpy.arange(arg) instead of what I

have done above? Something to do with the domain that I want to include in

the plot?

TIA,

Jon