5

I am trying to plot graph using matplotlib in Jupyter python notebook. But when I am assigning y axis label, its not showing in the graph and also it's plotting two graphs. The code which I am using is :

trans_count_month = df.groupby('month_').TR_AMOUNT.count() 
plt.xlabel('Months')  #X-axis label
plt.ylabel('Total Transactions Count') #Y-axis label 
plt.title("Month wise Total Transaction Count") #Chart title. 
width = 9
height = 5
plt.figure(figsize=(width, height))
trans_count_month.plot(kind='bar')
plt.figure(figsize=(width, height))

and the output which I am getting is: enter image description here

How I can show only one graph with y axis label also and if there is any other way to draw this graph please share the solution.

3
  • 1
    I would guess to just remove the first plt.figure(figsize=width, height)). Commented Aug 8, 2017 at 5:44
  • Try to change the order. The plt.xlabel/ylable/title should come after the .plot. Furthermore, use the figsize keyword argument of plot instead of plt.figure(figsize=()). Commented Aug 8, 2017 at 5:47
  • Thanks @Dror it's working now Commented Aug 8, 2017 at 6:01

1 Answer 1

8

Here is a minimal example:

import pandas as pd

%matplotlib inline
from matplotlib import pyplot as plt
import pandas as pd

s = pd.Series([1,2,3], index=['a','b','c'])

s.plot.bar(figsize=(20,10))
plt.xlabel('Foo')
plt.ylabel('Bar')
plt.title("Hello World");

enter image description here

Which better utilize pandas and matplotlib.

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

Comments

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.