-1

Following is the code to get display a Bar chart using Python (3.6). Once I execute the following program the chart disappears after 1 sec. Can anyone please help with this.

import pandas
import csv
import pandas as pd
import matplotlib


df2 =pandas.read_csv('Place.csv')
place_plot= df2.Place.value_counts().plot(kind="bar",x=df2["Place"],title="Count",legend=False)
fig = place_plot.get_figure() 
fig.show()

The Place.csv file has the following data,

Name    Place
A   India
B   USA
C   India
D   USA
E   China
F   UK
G   Canada
H   China
I   UK
J   UK
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712

1 Answers1

0

It depends on where and how you execute the code. In a notebook environment it should work fine. However if executed as a script, you should rather use

plt.show()

instead of fig.show().

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • Thanks a lot. Now its working :) – Skanda Udupa Apr 19 '17 at 15:17
  • I want to include one more graph in the program with CSV including one more column Capital ( Capitals of the countries), Im using following code, `capital_plot= output2.Capital.value_counts().plot(kind="bar",x=output2["Capital"],title="Count",legend=False) plt.show()` . I am getting the output but only after closing the 1st figure. Is it not possible to display 2 figures together? – Skanda Udupa Apr 20 '17 at 12:48
  • Yes, see e.g. [this question](http://stackoverflow.com/questions/1401102/python-with-matplotlib-drawing-multiple-figures-in-parallel) – ImportanceOfBeingErnest Apr 20 '17 at 12:52