Issue
I have to chart a data from csv somewhere from my directory. I am using python by learning some samples online. Problem is, I can't find any solution to show all x-axis labels.
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
pathcsv = r'D:\iPython\csvfile\samplecsv2.csv'
df = pd.read_csv(pathcsv)
df.set_index('Names').plot()
plt.show()
Solution
you can do that by using set_xticklabels
to set the names and set_xticks
to show ticks for each country. Updated code is below...
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
pathcsv = r'D:\iPython\csvfile\samplecsv2.csv'
ax =df.set_index('Names').plot()
ax.set_xticks(np.arange(len(df))) #Show ticks for each country
ax.set_xticklabels(df.Names) #Show labels as in df.Names
plt.show()
Output graph
Answered By - Redox
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.