0

I am having an issue plotting after a date has been plotted. the code is the following:

import matplotlib.pyplot as plt

from matplotlib import style

x = [735412.0, 735503.0, 735594.0, 735685.0]

y =['0.0', '16961000000.0', '29030000000.0', '32504000000.0']

z = ['100000', '200000000000', '3000000000000', '400000000000']



# plt.plot_date(x, y, marker='o', linestyle='-', color='b')

plt.plot(y,z) # this does not print if above line is uncommented

plt.gcf().autofmt_xdate() # turns bottom dates at angle

plt.show()

What am I doing wrong? Thanks! L

2
  • You don't have any dates to plot. I believe plot_date() will expect the first argument to be a list of datetime objects. Commented Jun 1, 2015 at 3:32
  • @Scott, no, the numbers in x are interpreted somehow as dates (hours since some reference or so, I am sure). Commented Jun 1, 2015 at 11:18

1 Answer 1

1

First of all, your "numbers" in y are actually strings. You would need to convert them to float using np.array(y, float) to use them on an axis.

But did you really intend to plt.plot(y,z) in the same figure as the others? The values in y are not dates/times of any kind, so probably not.

I suspect this should be a new figure, so you need to start a new figure with plt.figure() before you plot y vs z:

plt.figure()
plt.plot(y,z)

and drop the plt.gcf().autofmt_xdate() after that.

Sign up to request clarification or add additional context in comments.

2 Comments

THanks all, it looks like it makes no difference whether y is a list of strings of floats, they can be plotted individually with no problem. What I am trying to accomplish is to plot overlapping lines on the same figure like the following:x = [1,2,3] y = [2,3,4] z = [5,4,3] plt.plot(x,y) plt.plot(x,z) plt.show()
In that case you just have typo (y,z instead of the correct x,z).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.