Could someone please help me fix the matplotlib scatter plot x axis having 0.25 increments like below? Here is the Dataset My code is here
Could someone please help me fix the matplotlib scatter plot x axis having 0.25 increments like below? Here is the Dataset My code is here
As the year column is read as integer, matplotlib thinks that this is int. That is the reason for the multiple ticklables. Easiest way to do this is to convert the Year to a categorical(string) as you have just 3 years. That way, matplotlib will plot it with the values as strings.
Note that I have also read the columns of df to X,y directly without creating another dataframe. You don't require to convert a column into a dataframe as this will be a series. Just a small change for simplicity.
df = pd.read_csv('ds_salaries.csv')
X=df['work_year'].astype("string") ## Read as string
y=df['salary_in_usd']
plt.figure(figsize=(10,6))
plt.scatter(X,y, alpha=0.3)
plt.title ('Salary Trends for Data Science jobs')
plt.xlabel('Year')
plt.ylabel('Salary in USD')
plt.show()