Python Forum
Having trouble setting the X-Ticks for a data set I am working with.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having trouble setting the X-Ticks for a data set I am working with.
#2
My guess is that Date of Census in your homelessness_data is not a datetime or date object. I read your data like this:
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()
Reply


Messages In This Thread
RE: Having trouble setting the X-Ticks for a data set I am working with. - by deanhystad - Jan-22-2024, 09:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Passing data between functions, got it working, but need clarification please digitalmatic7 4 16,315 Apr-18-2018, 09:30 AM
Last Post: digitalmatic7
  I'm working onn below code to extract data from excel using python kiran 1 3,428 Oct-24-2017, 01:42 PM
Last Post: kiran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020