Jan-22-2024, 09:12 PM
(This post was last modified: Jan-22-2024, 09:12 PM by deanhystad.)
My guess is that Date of Census in your homelessness_data is not a datetime or date object. I read your data like this:
Compare the plot produced by this code:
I think this will fix your problem, but if you do want to set labels and the like (which is almost always a bad idea), you do this using the Axis object returned by sns.lineplot()
import pandas as pd data = pd.read_csv("census.csv") print(data.dtypes)
Output:Date of Census object
Total Individuals in Shelter int64
Total Single Adults in Shelter int64
Families with Children in Shelter int64
Adult Families in Shelter int64
dtype: object
Notice that Date of Census is an "object", which is a string. You need Date of Census to be a date, then seaborn/matplotlib can create ticks that are reasonable in count and distribution because it will know what the tics mean.Compare the plot produced by this code:
import pandas as pd import matplotlib.pyplot as plt data = pd.read_csv("census.csv") data.plot(x="Date of Census", y="Total Individuals in Shelter") plt.show()With the plot produced by this code.
import pandas as pd import matplotlib.pyplot as plt data = pd.read_csv("census.csv", parse_dates=["Date of Census"]) data.plot(x="Date of Census", y="Total Individuals in Shelter") plt.show()Matplotlib usually does a good job making tic marks and labels. When something goes wrong it is usually because you are not providing enough information for matplotlib to make good decisions.
I think this will fix your problem, but if you do want to set labels and the like (which is almost always a bad idea), you do this using the Axis object returned by sns.lineplot()