20
import pandas as pd
import matplotlib.pyplot as plt

file = 'd:\\a\\pandas\\test.xlsx'
data = pd.ExcelFile(file)
df1 = data.parse('Link')
df2 = df1[['dataFor', 'total']]
df2

returns:

enter image description here

 print (type(df2))

tells me

class 'pandas.core.frame.DataFrame'

trying

df2.plot(kind='line')

returns

matplotlib.axes._subplots.AxesSubplot at 0xe4241d0

Could it be the environment?

Jupyter notebook > Help > About

The version of the notebook server is 4.2.3 and is running on:
Python 3.5.2 |Anaconda 4.2.0 (32-bit)| (default, Jul  5 2016, 11:45:57) [MSC    v.1900 32 bit (Intel)]

Where is the fault? Is matplotlib still the standard or should beginners go for Bokeh or for both?

3
  • 1
    This is all fine and works as expected. What exactly is the problem? What would you expect and what happens instead? Commented Jan 27, 2017 at 16:24
  • 1
    I get matplotlib.axes._subplots.AxesSubplot at 0xe4241d0 message and no graphic shows up in the jupyter notebook. Commented Jan 27, 2017 at 16:25
  • I wouldn't recommend bokeh, unless you already know that you will only produce webgraphics. Commented Jan 27, 2017 at 16:28

3 Answers 3

51

In case you want to see the plot inline, use

%matplotlib inline

in the header (before the imports).

If you want to show the graphic in a window, add the line

plt.show()

at the end (make sure you have imported import matplotlib.pyplot as plt in the header).

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

3 Comments

missed plt.show() ... note to myself never post on friday late afternoon...
for anyone else looking for why missingno library is not displaying plots in a jupyter, use %matplotlib inline in single cell. (figured it out thanks to this answer)
%matplotlib inline place before the res.plot() not before import in jupyter.
4
## importing libraries
## notice to import %matplotlib inline to plot within notebook
import pandas as pd
%matplotlib inline
import matplotlib.pyplot as plt
import datetime


## making a DF like yours
df2 = pd.DataFrame([], columns=['dataFor','total'])
df2['dataFor'] = [datetime.datetime(2013, 9, 11),datetime.datetime(2013, 9, 12),datetime.datetime(2013, 9, 13),datetime.datetime(2013, 9, 14),datetime.datetime(2013, 9, 15),datetime.datetime(2013, 9, 16),datetime.datetime(2013, 9, 17)]
df2['total'] = [11,15,17,18,19,20,21]

## notice date are datetimes objects and not strings
df2.plot(kind='line')

output:

enter image description here

if one wants to improve graph layout:

plt.figure(figsize=(20,10))
plt.plot(df2.dataFor, df2.total, linewidth=5)
plt.plot(df2.dataFor, df2.total, '*', markersize=20, color='red')
plt.xticks(fontsize=20, fontweight='bold',rotation=90)
plt.yticks(fontsize=20, fontweight='bold')
plt.xlabel('Dates',fontsize=20, fontweight='bold')
plt.ylabel('Total Count',fontsize=20, fontweight='bold')
plt.title('Counts per time',fontsize=20, fontweight='bold')
plt.tight_layout()

enter image description here

Comments

0

I got the same problem on performing the plot but I got it solved by running the import clause followed by %matplotlib. I think I'm using the latest version. I've tried the " %matplotlib inline " but for some reasons, it doesn't work on my end.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.