Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to customize x axis in matplotlib.pyplot for a scatter plot?
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
tell us a bit about your code, environment, etc.
wlsa likes this post
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)
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?
see tutorial here:
wlsa likes this post
Or this, which I think directly addresses setting an axis to a date range:
wlsa likes this post
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.
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.
wlsa likes this post
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
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.
wlsa likes this post
Figured it out...
I just divided every value by 365

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How do I make my plot show up? ThomasM4 0 116 Dec-09-2018, 05:28 AM
Last Post: ThomasM4
  Tips on surface plot HW question Cwcox 1 180 Nov-14-2018, 11:45 PM
Last Post: Larz60+
  How to create custom error bars in matplotlib.pyplot? wlsa 1 221 Nov-04-2018, 09:49 PM
Last Post: wlsa
  Adding text to plot Pythcoronas 1 254 Sep-13-2018, 12:27 PM
Last Post: baby_quant
  plot the mean in a bar diagram sussii 3 385 May-23-2018, 11:27 PM
Last Post: wavic
  How to plot date series in matplotlib? StrybolData 2 1,627 Jan-25-2018, 07:13 PM
Last Post: StrybolData
  how to solve this problem. IndexError: axis 2 out of bounds [0, 2) bedio 10 1,977 Nov-21-2017, 02:47 PM
Last Post: heiner55
  Removing data in a plot ulrich48155 3 1,260 Jun-19-2017, 06:31 PM
Last Post: zivoni
  Pyplot line color and spacing/padding metalray 0 947 May-26-2017, 08:39 AM
Last Post: metalray
  How to plot a Graph Kamo 2 1,295 May-12-2017, 12:22 PM
Last Post: zivoni

Forum Jump:

Users browsing this thread: 1 Guest(s)