|
From: Benjamin R. <ben...@ou...> - 2011-09-17 20:16:32
|
On Saturday, September 17, 2011, Klonuo Umom <kl...@gm...> wrote:
> Hi,
> please consider this snippet:
> import matplotlib.pyplot as plt
> d={}
> for i in range(1,21):
> d[i] = i**2
> plt.plot(d.values())
> plt.xticks(d.keys())
> plt.show()
>
> As it can be seen from attached screenshot, xticks values are shifted to
right (by 1).
> Seems strange, but perhaps something to do with Python 0-start.
> So why plot starts at beginning of x-axis and xticks start shifted by 1?
> How does regular matplotlib users handle similar code?
> Thanks
When you called plot() with only the y values, mpl will assume x values as
range(len(y)). Just call plot with both x and y values.
Ben Root
|