Virgiliu
Virgiliu

Reputation: 3118

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=1, ms=6)
ax.plot(data2, '-o', color='#000000', lw=1, ms=6)

plt.show()

This creates a graph like the one below.

I need the second graph (the one using the data2 points) to start from 5 on the X axis, not from 0, meaning it'll have the points at (5,34),(6,25),(7,42),(8,53),(9,61). How can I do this?

Upvotes: 1

Views: 4067

Answers (1)

David Z
David Z

Reputation: 131550

Make a list of the X values,

x = [5,6,7,8,9]

and use

ax.plot(x, data2, ...)

Note that you could also use range(5,10) or numpy's arange(5,10) or linspace(5,9,5) to generate the X values.

Upvotes: 1

Related Questions