Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to display a .png file I constructed 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 appreciate your assistance.

I tried the following but no errors nor .png are displayed.

from PIL import Image
image = Image.open("titanic.png")
image.show()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
726 views
Welcome To Ask or Share your Answers For Others

1 Answer

if you just want to display it, you may use matplotlib:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...