Discussion:
[Matplotlib-users] xticks not lining up with data
Ted To
2015-06-17 14:13:03 UTC
Permalink
Hi,

I'm having a strange problem and I don't understand why this is
happening. I am plotting the dataframe in: http://pastebin.com/C0Pt0iYd
but I'm getting too few tick marks. My code for the plot is:

fig, ax = plt.subplots()
plt.rc('text', usetex=True)
fig.autofmt_xdate()
ax.plot(indices.carli,'b-',label=r'\textsf{Carli}')
ax.plot(indices.geomean,'g-',label=r'\textsf{GeoMean}')
ax.plot(indices.laspeyres,'c-',label=r'\textsf{Laspeyres}')
ax.plot(indices.paasche,'m-',label=r'\textsf{Paasche}')
ax.plot(indices.tornqvist,'y-',label=r'\textsf{T\"ornqvist}')
plt.xlabel(r'\textsf{Month}')
plt.ylabel(r'\textsf{Index value}')
ax.set_xticklabels(indices.index)

Any ideas what I'm doing wrong?

Thanks,
Ted
Benjamin Root
2015-06-17 14:28:49 UTC
Permalink
Why are you calling ax.set_xticklabels()?. Why not pass the x values to
ax.plot() along with the y values? Then you won't need to set the labels
because matplotlib will do it for you.

Ben Root
Post by Ted To
Hi,
I'm having a strange problem and I don't understand why this is
happening. I am plotting the dataframe in: http://pastebin.com/C0Pt0iYd
fig, ax = plt.subplots()
plt.rc('text', usetex=True)
fig.autofmt_xdate()
ax.plot(indices.carli,'b-',label=r'\textsf{Carli}')
ax.plot(indices.geomean,'g-',label=r'\textsf{GeoMean}')
ax.plot(indices.laspeyres,'c-',label=r'\textsf{Laspeyres}')
ax.plot(indices.paasche,'m-',label=r'\textsf{Paasche}')
ax.plot(indices.tornqvist,'y-',label=r'\textsf{T\"ornqvist}')
plt.xlabel(r'\textsf{Month}')
plt.ylabel(r'\textsf{Index value}')
ax.set_xticklabels(indices.index)
Any ideas what I'm doing wrong?
Thanks,
Ted
------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Ted To
2015-06-17 16:48:56 UTC
Permalink
Unless I recall incorrectly, I think I am using set_xticklabels because
indices.index are strings. When I tried specifying
ax.plot(indices.index,indices.carli) I get a ValueError.

Ted
Post by Benjamin Root
Why are you calling ax.set_xticklabels()?. Why not pass the x values
to ax.plot() along with the y values? Then you won't need to set the
labels because matplotlib will do it for you.
Ben Root
Post by Ted To
Hi,
I'm having a strange problem and I don't understand why this is
http://pastebin.com/C0Pt0iYd [1]
fig, ax = plt.subplots()
plt.rc('text', usetex=True)
fig.autofmt_xdate()
ax.plot(indices.carli,'b-',label=r'textsf{Carli}')
ax.plot(indices.geomean,'g-',label=r'textsf{GeoMean}')
ax.plot(indices.laspeyres,'c-',label=r'textsf{Laspeyres}')
ax.plot(indices.paasche,'m-',label=r'textsf{Paasche}')
ax.plot(indices.tornqvist,'y-',label=r'textsf{T"ornqvist}')
plt.xlabel(r'textsf{Month}')
plt.ylabel(r'textsf{Index value}')
ax.set_xticklabels(indices.index)
Any ideas what I'm doing wrong?
Thanks,
Ted
------------------------------------------------------------------------------
Post by Ted To
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users [2]
------
[1] http://pastebin.com/C0Pt0iYd
[2] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
------------------------------------------------------------------------------
Benjamin Root
2015-06-17 16:55:57 UTC
Permalink
Then convert them to date objects? Also, I am guessing that the length of
indices.index is not the same as indices.carli, which could also be the
reason for a ValueError. So you would need to use whatever pandas variable
that indices.index derived from.

Ben Root
Post by Ted To
Unless I recall incorrectly, I think I am using set_xticklabels because
indices.index are strings. When I tried specifying
ax.plot(indices.index,indices.carli) I get a ValueError.
Ted
Post by Benjamin Root
Why are you calling ax.set_xticklabels()?. Why not pass the x values
to ax.plot() along with the y values? Then you won't need to set the
labels because matplotlib will do it for you.
Ben Root
Hi,
Post by Ted To
I'm having a strange problem and I don't understand why this is
http://pastebin.com/C0Pt0iYd [1]
fig, ax = plt.subplots()
plt.rc('text', usetex=True)
fig.autofmt_xdate()
ax.plot(indices.carli,'b-',label=r'textsf{Carli}')
ax.plot(indices.geomean,'g-',label=r'textsf{GeoMean}')
ax.plot(indices.laspeyres,'c-',label=r'textsf{Laspeyres}')
ax.plot(indices.paasche,'m-',label=r'textsf{Paasche}')
ax.plot(indices.tornqvist,'y-',label=r'textsf{T"ornqvist}')
plt.xlabel(r'textsf{Month}')
plt.ylabel(r'textsf{Index value}')
ax.set_xticklabels(indices.index)
Any ideas what I'm doing wrong?
Thanks,
Ted
------------------------------------------------------------------------------
Post by Ted To
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users [2]
------
[1] http://pastebin.com/C0Pt0iYd
[2] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Ted To
2015-06-17 19:11:42 UTC
Permalink
Thank you, that worked. And also showed me why the xticks were
mismatched -- apparently my index was not sorted.
Post by Benjamin Root
Then convert them to date objects? Also, I am guessing that the length
of indices.index is not the same as indices.carli, which could also be
the reason for a ValueError. So you would need to use whatever pandas
variable that indices.index derived from.
Ben Root
Post by Ted To
Unless I recall incorrectly, I think I am using set_xticklabels
because indices.index are strings. When I tried specifying
ax.plot(indices.index,indices.carli) I get a ValueError.
Ted
Why are you calling ax.set_xticklabels()?. Why not pass the x
values
to ax.plot() along with the y values? Then you won't need to set the
labels because matplotlib will do it for you.
Ben Root
Hi,
I'm having a strange problem and I don't understand why this is
http://pastebin.com/C0Pt0iYd [1] [1]
fig, ax = plt.subplots()
plt.rc('text', usetex=True)
fig.autofmt_xdate()
ax.plot(indices.carli,'b-',label=r'textsf{Carli}')
ax.plot(indices.geomean,'g-',label=r'textsf{GeoMean}')
ax.plot(indices.laspeyres,'c-',label=r'textsf{Laspeyres}')
ax.plot(indices.paasche,'m-',label=r'textsf{Paasche}')
ax.plot(indices.tornqvist,'y-',label=r'textsf{T"ornqvist}')
plt.xlabel(r'textsf{Month}')
plt.ylabel(r'textsf{Index value}')
ax.set_xticklabels(indices.index)
Any ideas what I'm doing wrong?
Thanks,
Ted
------------------------------------------------------------------------------
Post by Ted To
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users [2]
[2]
------
[1] http://pastebin.com/C0Pt0iYd [1]
[2] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[2]
------
[1] http://pastebin.com/C0Pt0iYd
[2] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
------------------------------------------------------------------------------
Loading...