Incomplete X-Labels on Line Chart in Jupyter Notebook

My Code (in Jupyter Notebook):

import pandas as pd
import numpy as np
from matplotlib import pyplot as plt

unrate = pd.read_csv("unemployment-rate_csv.csv")
unrate.columns = ["DATE","VALUE"]
unrate["DATE"] = pd.to_datetime(unrate["DATE"])
first_12 = unrate[:12]

plt.plot(first_12["DATE"],first_12["VALUE"])
plt.xticks(rotation=90)
plt.xlabel("Month")
plt.ylabel("Unemployment Rate")
plt.title("Monthly Unemployment Trends, 1948")
plt.show()

What I expected to happen:

Display all x-labels for the 12 months of the year 1948.

What actually happened:

Only every 2nd label was shown: 1948-01, 1948-03, 1948-05, etc

I tried to replicate the unemployment rate line chart from the course “Line Charts” in Jupyter Notebook. I used the same code as in the DQ-environment but the number of x-labels was not the same. How can I display them all?

Thanks.

Hi @Ivan.M : To allow us in the community to understand the issue that you are facing, please include a link to your question and conform to these guidelines. Please also include a screenshot of your graph if possible.Thanks!

Hi,
the DQ course is this one
Here the 2 screenshots with identical code. The chart in Jupyter NB only displays half of the x-labels.

How to make it display all 12 months? Thanks.

Set the ticks with date values in plt.xticks()

plt.xticks(ticks=first_12["DATE"], rotation=90)
1 Like

Perfect! This did the job. Thank you.

1 Like