1

Python beginner here :/! The csv files can be found here (https://www.waterdatafortexas.org/groundwater/well/8739308)

#I'm trying to subset my data and plot them by years or every 6 months but I just cant make it work, this is my code so far

data=pd.read_csv('Water well.csv')

data["datetime"]=pd.to_datetime(data["datetime"])
data["datetime"]
fig, ax = plt.subplots()
ax.plot(data["datetime"], data["water_level(ft below land surface)"])
ax.set_xticklabels(data["datetime"], rotation= 90)

and this is my data and the output. As you can see, it only plots 2021 by time

This is my data of water levels from 2016 to 2021 and the output of the code

This is my data of water levels from 2016 to 2021 and the output of the code

data

data

7

2 Answers 2

3

When you run your script, you get the following warning:

UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.set_xticklabels(data["datetime"], rotation= 90)

Your example demonstrates, why they included this warning.
Comment out your line

#ax.set_xticklabels(data["datetime"], rotation= 90)

and you have the following (correct) output:

enter image description here

Your code takes now the nine automatically generated x-axis ticks, removes the correct labels, and labels them instead with the first nine entries of the dataframe. Obviously, these labels are wrong, and this is the reason they provide you with the warning - either let matplotlib do the automatic labeling or do both using FixedFormatter and FixedLocator to ensure that tick positions and labels match.
For more information on Tick locators and formatters consult the matplotlib documentation.

P.S.: You also have to invert the y-axis because the data are in ft below land surface.

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

5 Comments

Thank you so much @Mr. T! UGhh i felt soo stupid lmaooo
one last thing what do you mean by inverting the y-axis, yes i do understand that the data are in ft below land surface
If this answer solved your problem, please consider accepting it.
Regarding your question - the website that provided these data presents the data with an inverted y-axis, so that increases and decreases correspond with our understanding of rising and falling levels. You can achieve this in your plot with ax.invert_yaxis(). And don't worry about making mistakes - we are all here to learn from each other.
ohh like flip it! sorry!
0

The problem is, you have too much data, you have to simplify it.

At first you can try to do something like this:

data["datetime"]=pd.to_datetime(data["datetime"])
date = data["datetime"][0::1000][0:10]
temp = data["water_level(ft below land surface)"][0::1000][0:10]
fig, ax = plt.subplots()
ax.plot(date, temp)
ax.set_xticklabels(date, rotation= 90)

date = data["datetime"][0::1000][0:10]

This line mean: take the index 0, then 1000, then 2000, ...

So you will have an new array. And then with this new array you just take the first 10 indexes.

It's a dirty solution

The best solution in my opinion is to create a new dataset with the average temperature for each day or each week. And after you display the result

1 Comment

I think the tick labels are not in the right order.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.