Not able to make x axis ticks start properly

Viewed 57

I've been trying to make graphs about covid-19, by starting couting from the first day in which there is more or equal to 100 cases on the country, but my axis doesn't seem to fit the way that i want, and none of the solutions i looked up seemed to work properly. here is the graph and the way i wanted it to be.

The blue drawings is how i want it to be.

Graph

# IMPORTING MODULES

import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt

# READING CSV FILE
df = pd.read_csv('time_series_covid19_confirmed_global.csv')

# GROUPING DATA BY COUNTRY
df = df.groupby('Country/Region').sum()

# DROPPING LATITUDE AND LONGITUDE
df = df.drop(['Lat', 'Long'], axis=1).reset_index()

#SETTING Y AXIS
selected_countries = ['Argentina',
                      'Brazil',
                      'Chile',
                      'Ecuador',
                      'Peru',
                      'Colombia',
                      'Venezuela',
                      'Ecuador',
                      'Uruguay'
]
y_axis_parse1 = df.loc[df['Country/Region'] == 'Brazil'].values[0]
y_axis = [x for x in y_axis_parse1[1:] if x >= 100]  # Setting starting point to 100 cases

#SETTING X AXIS
x_axis = range(len(y_axis))  # x axis based on lenght of y list data

#PLOTTING
plt.plot(x_axis, y_axis, '.-', color='red')
plt.xticks(x_axis)
plt.grid()

# STYLE OF THE GRAPH
plt.style.use('ggplot')

#PLOT SHOW
plt.show()
1 Answers

It looks like you are looking for

plt.xlim(left=0)

That will make your data start at the left edge of the chart.

Related