3

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

2 Answers2

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'])

enter image description here

jakevdp
  • 77,104
  • 11
  • 125
  • 160
  • thanks, it works when I precise ```kind='bar``` , but it's strange for me why when I don't precise this argument and I want just line and not bar plot, the same pandas plotting functions don't put all the row names as labels on the axis? (but still plot beautiful line plot) –  Nov 18 '15 at 09:23
0

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')

enter image description here

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.

Community
  • 1
  • 1
Luis Miguel
  • 5,057
  • 8
  • 42
  • 75
  • 1
    thanks! I upvote your answer, but I marked the first one as correct, cause of works for me, and it seems to be shorter and though more beautiful! I don't want cumulative chart but just line chart, and it turns out that without precising the ```kind='bar'``` it doesn't plot all the names as labels of x axis, and just 8 from 430. but it works well with ```kind='bar'``` , still I'm looking for solution to plot line chart, and have all the row names as labels of X axe –  Nov 18 '15 at 09:30