Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting graph using matplotlib in Jupyter iPython Notebook

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.

like image 739
neha Avatar asked Aug 08 '17 05:08

neha


People also ask

Can you use matplotlib in Jupyter notebook?

IPython kernel of Jupyter notebook is able to display plots of code in input cells. It works seamlessly with matplotlib library.

What is used to display plots on the Jupyter notebook?

The %matplotlib magic command sets up your Jupyter Notebook for displaying plots with Matplotlib. The standard Matplotlib graphics backend is used by default, and your plots will be displayed in a separate window.

How do I add matplotlib to Jupyter?

Make sure you first have Jupyter notebook installed, then we can add Matplotlib to our virtual environment. To do so, navigate to the command prompt and type pip install matplotlib. Now launch your Jupyter notebook by simply typing jupyter notebook at the command prompt.


1 Answers

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.

like image 51
Dror Avatar answered Oct 08 '22 22:10

Dror