Issue
some weeks ago I wrote this code which was working but I had to reinstall Anaconda in the meantime and now it's not working anymore. I don't understand why this error occurs now. The index of my dataframe contains the dates. Thank you for the help !
when I write:
plt.figure(figsize=(13,10))
from matplotlib import cycler
colors = cycler('color',
['#FFBBBB', '#3388BB', '#9988DD',
'#EECC55', '#88BB44', '#EE6666'])
plt.rc('axes', facecolor='#E6E6E6', edgecolor='none',
axisbelow=True, grid=True, prop_cycle=colors)
plt.rc('grid', color='w', linestyle='solid')
plt.rc('xtick', direction='out', color='gray')
plt.rc('ytick', direction='out', color='gray')
plt.rc('patch', edgecolor='#E6E6E6')
plt.rc('lines', linewidth=2)
plt.subplot(3, 1, 1)
l1 = plt.plot(data.index, data["E153"])
l2 = plt.plot(data.index, data["E159"])
l3 = plt.plot(data.index, data["E161"])
l4 = plt.plot(data.index, data["T13"])
l5 = plt.plot(data.index, data["T21"])
l6 = plt.plot(data.index, data["T22"])
plt.xlim(("1999-05-01","1999-11-30"))
plt.ylim(-0.1, 1.5)
plt.grid(True)
plt.subplot(3, 1, 2)
plt.plot(data.index, data["E153"])
plt.plot(data.index, data["E159"])
plt.plot(data.index, data["E161"])
plt.plot(data.index, data["T13"])
plt.plot(data.index, data["T21"])
plt.plot(data.index, data["T22"])
plt.xlim(("2000-05-01","2000-11-30"))
plt.ylim(-0.1, 1.5)
plt.grid(True)
plt.subplot(3, 1, 3)
plt.plot(data.index, data["E153"])
plt.plot(data.index, data["E159"])
plt.plot(data.index, data["E161"])
plt.plot(data.index, data["T13"])
plt.plot(data.index, data["T21"])
plt.plot(data.index, data["T22"])
plt.xlim(("2001-05-01","2001-11-30"))
plt.ylim(-0.1, 2)
plt.grid(True)
line_labels = ["E153", "E159", "E161", "T13", "T21", "T22"]
plt.figlegend([l1, l2, l3, l4, l5, l6],
labels= line_labels,
loc="center right",
bbox_to_anchor=(1.1, 0.5),
title="Légende")
plt.tight_layout()
plt.show()
It says :
ConversionError: Failed to convert value(s) to axis units: '1999-05-01'
Here's a screen of the situation, you can see the all thing with my DataFrame and stuff
Solution
If your x-axis is dates you would need to do:
plt.xlim((pd.to_datetime("1999-05-01"),pd.to_datetime("1999-11-30")))
And the same for your other .xlim()
calls.
Answered By - mechanical_meat
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.