0
df = pd.DataFrame({'id':['abc1', 'abc2', 'abc3','abc4'], 'age':[21,23,45,34],
'marks':[20, 24, 34, 18]})
 df 

So I want to plot a bar chart with x axis being the age group.
Say I want my groups to be :

10-20, 20-30, 30-40, 40-50

I am new to plotting in Python Can you please help.

2
  • Given that you want age groups on the x-axis, can you clarify what you want on the y-axis? For example: average marks in the age group? Commented Jan 13, 2015 at 5:23
  • frequency of people in the age group. Commented Jan 13, 2015 at 5:25

2 Answers 2

1

I would use the matplotlib library for this.

import matplotlib.pyplot as plt
import numpy as np

def plot_histogram_06():
    data = np.random.normal(loc=30, scale=10, size=[1000, 1])
    bins = (10, 20, 30, 40, 50, 60, 70)
    plt.hist(data, bins=bins)
    plt.savefig('my_plot_06.png')
    plt.close()

Histogram for age

You can add normed=True in the hist argument list if you want to normalize the y-axis. For further options, I refer to the matplotlib manual.

Sign up to request clarification or add additional context in comments.

Comments

0
import pandas as pd
df = pd.DataFrame({'id':['abc1', 'abc2', 'abc3','abc4'], 'age':[21,23,45,34], 'marks':[20, 24, 34, 18]})
df['age'].hist(bins=[10,20,30,40,50])

enter image description here

1 Comment

thanks but my data is huge so I want x axis to be groups rather than particular age also I want y axis to be the frequency of people falling in that age group.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.