Graph Axis Markings not showing

here is my code:

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()

# Import data (Make sure to parse dates. Consider setting index column to 'date'.)
df = pd.read_csv("/content/drive/MyDrive/google-colab-data/fcc-forum-pageviews.csv")
print(df)


# Clean data
df = df[(df['value'] <= df['value'].quantile(.975)) & (df['value'] >= df['value'].quantile(.025))]


def draw_line_plot():
    # Draw line plot
    plt.plot(df["date"], df["value"])
    plt.title("Daily freeCodeCamp Forum Page Views 5/2016-12/2019")
    plt.xlabel("Date")
    plt.ylabel("Page Views")
    fig = plt





    # Save image and return fig (don't change this part)
    fig.savefig('line_plot.png')
    return fig

and when I run this code, the graph show up fine, but the axis markings don’t show

here is my output:

You can define the axis and margins in matplotlib, there are different forms, you could use axis.margins() or matplotlib.pyplot.margins
For example.
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.margins.html#matplotlib.pyplot.margins
you can see more examples here:

Hope this helps.

The problem is there is a black bar over my labels, so I am not sure if these functions will help?

It is not a black bar but actual df['value'] from your dataframe. It looks like a black bar because of the quantity of values involved (you are working with time series after all) all of these values are written one over the other as x-tick labels.
That is the reason why I recommended ticks, ticks are included in the documentation recommended above:
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.xticks.html#matplotlib.pyplot.xticks
for example:
ticks = plt.xticks(pos[::15], df['value'].values[::15], rotation=90)

If you still do not believe me, you can check by yourself in the documentation, or in:
https://jakevdp.github.io/PythonDataScienceHandbook/04.10-customizing-ticks.html

Hope this helps

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.