python进行数据可视化,下面通过案例进行讲解,在我们写论文时候使用起来相当方便。
导入pyplot进行绘制
import matplotlib.pyplot 绘图。
模块的简单调用
举例如下:绘制1-9的结果平方。
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 09:08:42 2020
@author: xu
"""
import matplotlib.pyplot as plt
input_value = [1,2,3,4,5,7,8,9]
squares = []
for i in range(0,len(input_value)):
squares.append(input_value[i]*input_value[i])
print(squares)
plt.plot(input_value,squares,linewidth=1)#绘制输入的结果和值的结果
plt.title("xixi",fontsize=15)#标题
plt.xlabel("value",fontsize=15)#横坐标
plt.ylabel("squares",fontsize=15)#纵坐标
plt.show()#显示
结果如下:
可以对颜色进行处理,使得颜色分布更加均匀:
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 09:23:11 2020
@author: xusir
"""
import matplotlib.pyplot as plt
#手工输入
#value = [1,2,3,4,5]
#scatter_squares = [1,8,27,64,125]
#循环输入
value = list(range(1,5001))
scatter_squares = [(x**2)**2 for x in value]
plt.scatter(value,scatter_squares,c = scatter_squares,cmap=plt.cm.Reds,edgecolors="none",s = 40)
plt.title("scatter_squares",fontsize = 20)
plt.xla