How to customize x axis in matplotlib.pyplot for a scatter plot? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: How to customize x axis in matplotlib.pyplot for a scatter plot? (/thread-13973.html) |
How to customize x axis in matplotlib.pyplot for a scatter plot? - wlsa - Nov-09-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 RE: How to customize x axis in matplotlib.pyplot for a scatter plot? - Larz60+ - Nov-09-2018 tell us a bit about your code, environment, etc. RE: How to customize x axis in matplotlib.pyplot for a scatter plot? - wlsa - Nov-09-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? RE: How to customize x axis in matplotlib.pyplot for a scatter plot? - Larz60+ - Nov-09-2018 see tutorial here: https://matplotlib.org/tutorials/introductory/pyplot.html#sphx-glr-tutorials-introductory-pyplot-py RE: How to customize x axis in matplotlib.pyplot for a scatter plot? - CanadaGuy - Nov-09-2018 Or this, which I think directly addresses setting an axis to a date range: https://matplotlib.org/gallery/text_labels_and_annotations/date.html RE: How to customize x axis in matplotlib.pyplot for a scatter plot? - wlsa - Nov-09-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. RE: How to customize x axis in matplotlib.pyplot for a scatter plot? - CanadaGuy - Nov-09-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. RE: How to customize x axis in matplotlib.pyplot for a scatter plot? - wlsa - Nov-09-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 RE: How to customize x axis in matplotlib.pyplot for a scatter plot? - CanadaGuy - Nov-09-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. RE: How to customize x axis in matplotlib.pyplot for a scatter plot? - wlsa - Nov-10-2018 Figured it out... I just divided every value by 365 |