Posts: 28
Threads: 15
Joined: May 2018
I have a list of 8698 temperatures which I want to plot on a scatter plot. How do I set the x-axis ticks labeled to a list of years? The list of years I have isn't as long as the temperature list, so I'm getting the ValueError: x and y must be the same size
Posts: 12,030
Threads: 485
Joined: Sep 2016
tell us a bit about your code, environment, etc.
Posts: 28
Threads: 15
Joined: May 2018
I only have 3 lists.
One is temp_list, which contains 8698 temperatures.
The second one is date_list, which 8698 dates in the format of m/d/y.
The last one is simply 'x', and it contains the number 1 up to 8698, which I'm currently using as the x axis.
Currently, I'm creating a scatter plot as follows
import matplotlib.pyplot as plt
plt.scatter(x, temp_list)
plt.show() This creates a scatter plot, but the x axis has ticks at 0, 2000, 4000, 6000, and 8000.
How do I change these numbers to 1996, 2001, 2006, 2011, 2016?
Posts: 12,030
Threads: 485
Joined: Sep 2016
Posts: 22
Threads: 6
Joined: Nov 2018
Or this, which I think directly addresses setting an axis to a date range:
https://matplotlib.org/gallery/text_labe.../date.html
Posts: 28
Threads: 15
Joined: May 2018
Maybe I wasn't clear enough.
I want the plot to look exactly the same, just 0 to read 1996, 2000 to read 2001, 4000 to read 2006, 6000 to read 2011, and 8000 to read 2016.
I couldn't see how to do that in either of the links posted, sorry if I missed it.
Posts: 22
Threads: 6
Joined: Nov 2018
Can't promise anything, but you could post a truncated version of your data (maybe 10 points or so) so we can see exactly what it looks like.
Posts: 28
Threads: 15
Joined: May 2018
It's just a list of floats
x=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
temp_list=[52.2, 38.5, 42.0, 41.2, 37.2, 52.1, 51.8, 51.0, 62.4, 68.7, 72.4, 71.6, 60.5, 53.3, 51.3, 56.1, 62.8, 65.4, 48.6]
plt.scatter(x, temp_list)
# each x value refers to the days since 1996
Posts: 22
Threads: 6
Joined: Nov 2018
Your first step would probably be to convert your date list from the current format, to a Python supported date format. Once you have that, then plotting the date list should look like the link I posted. That will associate your data with a real date, and you can go from there. Right now, Python or Matplotlib doesn't recognize your data as a date.
Posts: 28
Threads: 15
Joined: May 2018
Figured it out...
I just divided every value by 365
|