python编程从入门到实践-p286matplotlib安装及数据可视化
程序员文章站
2022-03-05 11:38:29
...
python编程从入门到实践-p286安装matplotlib
教程 https://blog.csdn.net/Jia_jinjin/article/details/80428598
下一步,先进python环境
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()
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()
15.2.3散点图
import matplotlib.pyplot as plt
plt.scatter(2,4)#坐标
plt.show()
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()
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()
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()
实际上,是散点组成的。
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()
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()
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()
上一篇: libigl + visual studio 2017 配置
下一篇: numpy初认识
推荐阅读
-
《Python编程:从入门到实践》个人学习笔记/心得(菜鸟瞎扯淡) Chapter2 变量和简单数据类型
-
【Python编程:从入门到实践】第十五章:生成数据
-
《Python编程从入门到实践》项目2 生成数据, 折线图, 随机漫步, pygal
-
Python中遍历整个列表及注意点(参考书籍Python编程从入门到实践)
-
《Python编程:从入门到实践》第二章 变量和简单数据类型 习题答案
-
《Python编程:从入门到实践》第二章 变量和简单数据类型 习题答案
-
Python学习:数据可视化之使用API (python从入门到实践),问题发现(17.2.1:改进Pygal图表与17.2.3:根据数据绘图)
-
Python编程:从入门到实践-项目2-数据可视化-matplotlib.pyplot-Demo
-
python从入门到实践-项目实战二数据可视化-生成数据
-
Python编程从入门到实战15章——数据可视化