python数据可视化,几个最简单的例子
import matplotlib.pyplot as plt import seaborn as sns import pandas as pd # 简单的折线图绘制 # x = [1, 2 ,3 ,4, 5] # y = [1, 4, 9, 16, 25] # plt.plot(x, y, linewidth = 5) # plt.title('example code', fontsize = 40, color = 'red') # plt.xlabel('value',fontsize = 20, color = 'blue') # plt.ylabel('vertical', fontsize = 20, color = 'blue') # plt.tick_params(axis = 'both', labelsize = 14) # plt.show() # 散点图绘制 # x = [1, 2, 3] # y = [2, 4, 6] # plt.scatter(x, y, color = 'red', s = 2000) # plt.show() # 绘制加了颜色随某一变量变化的散点图 # x = list(range(1, 1001)) # y = [n**2 for n in x] # # c=y,设置颜色变量随y值而变化,cmp=...设置颜色值 # plt.scatter(x, y, c = y, cmap = plt.cm.Reds, s = 80) # plt.show() # 应用seaborn模块设置主题样式 # sns.set_style('whitegrid') # x = list(range(1, 1001)) # y = [n**2 for n in x] # # c=y,设置颜色变量随y值而变化,cmp=...设置颜色值 # plt.scatter(x, y, c = y, cmap = plt.cm.Reds, s = 80) # plt.show() #读取txt格式文件并绘制直方图 df_iris = pd.read_table('df_iris.txt') # sns.distplot(df_iris['petal_length'],kde = True) plt.plot(df_iris['petal_length'],df_iris['petal_width']) plt.show()