您的位置:首页 > 编程语言 > PHP开发

matplotlib.pyplot 画图相关

2018-01-04 20:40 676 查看

matplotlib.pyplot 画图相关

本文主要介绍使用matplotlib.pyplot进行简单图像绘制:

matplotlib.pyplot是python中的绘图模块

from sklearn import datasets
import matplotlib.pyplot as plt
import pandas as pd
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
scikit_iris = datasets.load_iris()
iris = pd.DataFrame(data=np.c_[scikit_iris['data'],scikit_iris['target']],columns=np.append(scikit_iris.feature_names,['y']))
x = iris.index.values
y = iris['petal length (cm)'].values
plt.plot(x,y,'--')
plt.bar(x,y)  画柱状图
plt.scatter(x,y)   画散点图
plt.hsit(y) 画分布图
plt.boxplot(y)  画箱图
plt.loglog(x,y)  画对数图
plt.show()
plt.imwrite()  保存图片

#画圆
theta = np.arange(0, 2 * np.pi + 0.1,2 * np.pi / 1000)
x = np.cos(theta)
y = np.sin(theta)
v = 5
x = v * x
y = v * y
plt.plot(x, y, color='red')
plt.show()


x,y都是np.array类型的数据 dataframe中通过df.values 可以得到相应的数据
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: