问题
I have the dataframe that contains about 430 rows:
name Right_Answers Wrong_Answers
Alice Ji 7 6
Eleonora LI 2 5
Mike The 6 5
Helen Wo 5 3
for visualize the number of right (red) and wrong (blue) answers I'm using the matplotlib library with following functions:
g=df.plot(x='name', color=['b','r'], figsize=(100,50))
ax.xaxis.set_major_locator(MultipleLocator(0.1))
labels = df.name.values[:]
ax = plt.gca()
ax.set_xticklabels(labels, rotation=90)
but I have always only 8 names as labels on X axis, instead of 430 (rotated vertically, so there are enough of space for much more row names)! why it happens? I thought this method put all the row names on axis labels = df.name.values[:]
but apparently not.
do you know other solution for this problem?
I'm ready to try another libraries as seaborn or ggplot, even if I haven't found them very comfortable for dataframe compared with matplotlib
回答1:
Assuming your data is in a dataframe, you can use Pandas' built-in plotting methods, e.g.:
df.plot(kind='bar', color=['red', 'blue'])
回答2:
Try this (iPython notebook):
import pandas as pd
import matplotlib.pyplot as plt
%pylab inline
mydata = [{'Name':'John', 'TRUE_ANSWER': 75, 'FALSE_ANSWER':25},
{'Name':'Mike', 'TRUE_ANSWER': 60, 'FALSE_ANSWER':40},]
df = pd.DataFrame(mydata)
columns = ['Name','TRUE_ANSWER', 'FALSE_ANSWER']
df = df[columns]
df.index=df["Name"]
df.plot(kind='bar')
I think that trying to do the cumulative chart chart you asked me about in question plotting & formatting seaborn chart from pandas dataframe will not work with your set. Hope this helps.
来源:https://stackoverflow.com/questions/33763678/how-to-label-axis-with-all-the-row-names-from-dataframe