欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python编程从入门到实践-p286matplotlib安装及数据可视化

程序员文章站 2022-03-05 11:38:29
...

python编程从入门到实践-p286安装matplotlib
教程 https://blog.csdn.net/Jia_jinjin/article/details/80428598

python编程从入门到实践-p286matplotlib安装及数据可视化

下一步,先进python环境

python编程从入门到实践-p286matplotlib安装及数据可视化

15.2绘制简单折线图

import matplotlib.pyplot as plt
squares = [1,4,9,16,25]
plt.plot(squares)
plt.show()

15.2.1

python数据分析与展示-Matplotlib基础https://blog.csdn.net/weixin_40793311/article/details/89669287

import matplotlib.pyplot as plt
squares = [1,4,9,16,25]
plt.plot(squares,linewidth = 5)
plt.title("title",fontsize = 24)
plt.xlabel("xlabel",fontsize = 14)
plt.ylabel("ylabel",fontsize = 14)
plt.tick_params(axis = 'both',labelsize = 14)
plt.show()

python编程从入门到实践-p286matplotlib安装及数据可视化

15.2.2矫正图形

import matplotlib.pyplot as plt

input_values = [1,2,3,4,5]
squares = [1,4,9,16,25]
plt.plot(input_values,squares,linewidth = 5)
plt.title("title",fontsize = 24)
plt.xlabel("xlabel",fontsize = 14)
plt.ylabel("ylabel",fontsize = 14)
plt.tick_params(axis = 'both',labelsize = 14)
plt.show()

python编程从入门到实践-p286matplotlib安装及数据可视化

15.2.3散点图

import matplotlib.pyplot as plt

plt.scatter(2,4)#坐标
plt.show()

python编程从入门到实践-p286matplotlib安装及数据可视化

import matplotlib.pyplot as plt

plt.scatter(2,4,s = 2000)#s是点的大小 
plt.title("title",fontsize = 24)
plt.xlabel("xlabel",fontsize = 14)
plt.ylabel("ylabel",fontsize = 14)
plt.tick_params(axis = 'both',which = 'major',labelsize = 14)

plt.show()

python编程从入门到实践-p286matplotlib安装及数据可视化

15.2.4散点图

import matplotlib.pyplot as plt

x_values = [1,2,3,4,5]
y_values = [1,4,9,16,25]

plt.scatter(x_values,y_values,s = 100) 
plt.title("title",fontsize = 24)
plt.xlabel("xlabel",fontsize = 14)
plt.ylabel("ylabel",fontsize = 14)
plt.tick_params(axis = 'both',which = 'major',labelsize = 14)

plt.show()

python编程从入门到实践-p286matplotlib安装及数据可视化

15.2.5自动计算

import matplotlib.pyplot as plt

x_values = list(range(1,1001))
y_values = [x**2 for x in x_values]

plt.scatter(x_values,y_values,s = 10) 
plt.title("title",fontsize = 20)
plt.xlabel("xlabel",fontsize = 14)
plt.ylabel("ylabel",fontsize = 14)
plt.tick_params(axis = 'both',which = 'major',labelsize = 14)
plt.axis([0,1100,0,1100000])

plt.show()

python编程从入门到实践-p286matplotlib安装及数据可视化

python编程从入门到实践-p286matplotlib安装及数据可视化

实际上,是散点组成的。

edgecolor = 'none'没看到有何差别。

15.2.7自定义颜色

import matplotlib.pyplot as plt

x_values = list(range(1,1001))
y_values = [x**2 for x in x_values]

#plt.scatter(x_values,y_values,c='red',edgecolor = 'none',s = 10) 
plt.scatter(x_values,y_values,c=(0.8,1,1),edgecolor = 'none',s = 10) 
plt.title("title",fontsize = 20)
plt.xlabel("xlabel",fontsize = 14)
plt.ylabel("ylabel",fontsize = 14)
plt.tick_params(axis = 'both',which = 'major',labelsize = 14)
plt.axis([0,1100,0,1100000])

plt.show()

python编程从入门到实践-p286matplotlib安装及数据可视化

15.2.8颜色映射

import matplotlib.pyplot as plt

x_values = list(range(1,1001))
y_values = [x**2 for x in x_values]
 
plt.scatter(x_values,y_values,c=y_values,cmap = plt.cm.Blues,edgecolor = 'none',s = 10) 
plt.title("title",fontsize = 20)
plt.xlabel("xlabel",fontsize = 14)
plt.ylabel("ylabel",fontsize = 14)
plt.tick_params(axis = 'both',which = 'major',labelsize = 14)
plt.axis([0,1100,0,1100000])

plt.show()

python编程从入门到实践-p286matplotlib安装及数据可视化

15.2.9自动保存图表到原文件夹

import matplotlib.pyplot as plt

x_values = list(range(1,1001))
y_values = [x**2 for x in x_values]
 
plt.scatter(x_values,y_values,c=y_values,cmap = plt.cm.Blues,edgecolor = 'none',s = 10) 
plt.title("title",fontsize = 20)
plt.xlabel("xlabel",fontsize = 14)
plt.ylabel("ylabel",fontsize = 14)
plt.tick_params(axis = 'both',which = 'major',labelsize = 14)
plt.axis([0,1100,0,1100000])

plt.savefig('squares_plot.png',bbox_inches = 'tight')
# plt.show()