title: Plotting decision tree, graphvizm pydotplus
body: <p>I'm following the tutorial for decision tree on <a href="http://scikit-learn.org/stable/modules/tree.html" rel="noreferrer">scikit</a> documentation. 
  I have <code>pydotplus 2.0.2</code> but it is telling me that it does not have <code>write</code> method - error below. I've been struggling for a while with it now, any ideas, please?  Many thanks!</p>
  
  <pre><code>from sklearn import tree
  from sklearn.datasets import load_iris
  
  iris = load_iris()
  clf = tree.DecisionTreeClassifier()
  clf = clf.fit(iris.data, iris.target)
  
  from IPython.display import Image
  
  dot_data = tree.export_graphviz(clf, out_file=None)
  import pydotplus
  
  graph = pydotplus.graphviz.graph_from_dot_data(dot_data)
  
  Image(graph.create_png())
  </code></pre>
  
  <p>and my error is </p>
  
  <pre><code>    /Users/air/anaconda/bin/python /Users/air/PycharmProjects/kiwi/hemr.py
  Traceback (most recent call last):
    File "/Users/air/PycharmProjects/kiwi/hemr.py", line 10, in &lt;module&gt;
      dot_data = tree.export_graphviz(clf, out_file=None)
    File "/Users/air/anaconda/lib/python2.7/site-packages/sklearn/tree/export.py", line 375, in export_graphviz
      out_file.write('digraph Tree {\n')
  AttributeError: 'NoneType' object has no attribute 'write'
  
  Process finished with exit code 1
  </code></pre>
  
  <p>----- UPDATE -----</p>
  
  <p>Using the fix with <code>out_file</code>, it throws another error:</p>
  
  <pre><code> Traceback (most recent call last):
    File "/Users/air/PycharmProjects/kiwi/hemr.py", line 13, in &lt;module&gt;
      graph = pydotplus.graphviz.graph_from_dot_data(dot_data)
    File "/Users/air/anaconda/lib/python2.7/site-packages/pydotplus/graphviz.py", line 302, in graph_from_dot_data
      return parser.parse_dot_data(data)
    File "/Users/air/anaconda/lib/python2.7/site-packages/pydotplus/parser.py", line 548, in parse_dot_data
      if data.startswith(codecs.BOM_UTF8):
  AttributeError: 'NoneType' object has no attribute 'startswith'
  </code></pre>
  
  <p>---- <strong>UPDATE 2</strong> -----</p>
  
  <p>Also, se my own answer below which solves another problem</p>