Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I am attempting to show a .png file I developed using the following 

import pydot, StringIO

dot_data = StringIO.StringIO() 

tree.export_graphviz( clf, out_file = dot_data,    

feature_names =['age', 'sex', 'first_class', 'second_class', 'third_class'])

graph = pydot.graph_from_dot_data( dot_data.getvalue())

graph.write_png('titanic.png') 

from IPython.core.display import Image

Image( filename ='titanic.png')

I have never done this and would value your help. 

I attempted the following however no error nor .png are shown.

from PIL import Image

image = Image.open("titanic.png")

image.show()

1 Answer

0 votes
by (26.4k points)
edited by

You can try using matplotlib to diplay it. Try the below code:

import matplotlib.pyplot as plt

import matplotlib.image as mpimg

img = mpimg.imread('file-name.png')

plt.imshow(img)

plt.show()

Want to learn the concept of python in detail? Come and join the python course fast!

Watch the following video tutorial on how to become a professional in python

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...