[英]Writing Sci-Kit Learn Matplotlib Example to File
I'm trying to test out an example I found in a sci-kit learn tutorial but modify it so that I can write the resulting charts to a file. 我正在尝试测试在sci-kit学习教程中找到的示例,但请对其进行修改,以便可以将结果图表写入文件中。 According to the documentation the best way to write to a file is:
根据文档,写入文件的最佳方法是:
with open('path\file', 'w') as f:
f.write()
However, to my eyes at least there isn't a clear object to place as an argument in f.write()
. 但是,至少在我看来,
f.write()
没有明确的对象作为参数。 What is the best way to fix this? 解决此问题的最佳方法是什么? Is the only option to simply find a way to some how wrap up all the separate plot features (eg
plt.xlabel("Sepal Length")
) and reference that? 是唯一找到某种方式包装所有单独的绘图特征(例如
plt.xlabel("Sepal Length")
)并引用该方法的唯一选择吗? See below for the code. 参见下面的代码。
from __future__ import division
from sklearn import datasets
import matplotlib.pyplot as plt
import seaborn as sns
#matplotlib inline
sns.set(style='ticks', palette='Set2')
import pandas as pd
import numpy as np
import math
data = datasets.load_iris()
X = data.data[:100, :2]
y = data.target[:100]
X_full = data.data[:100, :]
setosa = plt.scatter(X[:50,0], X[:50,1], c='b')
versicolor = plt.scatter(X[50:,0], X[50:,1], c='r')
plt.xlabel("Sepal Length")
plt.ylabel("Sepal Width")
plt.legend((setosa, versicolor), ("Setosa", "Versicolor"))
sns.despine()
with open('path\file', 'w') as f:
f.write()
不确定您要问的是什么,但据我了解,请尝试
pylab.savefig('foo.png') pylab.savefig('foo.pdf')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.