【北京理工大学-Python 数据分析-2.1Matplotlib库入门】

本文介绍了Python的Matplotlib库,重点讲解了matplotlib.pyplot模块的使用,包括绘图区域、曲线格式设置、颜色和线条风格,以及如何处理中文显示问题。通过plt.plot()函数的参数说明,展示了如何定制图形的细节。还提到了plt.annotate()函数和 subplot2grid()函数在创建子绘图区域中的应用。
摘要由CSDN通过智能技术生成

Matplotlib库的使用

  • Matplotlib库由各种可视化类构成,内部结构复杂,受Matlab启发。
  • matplotlib.pyplot是绘制各类可视化图形的命令字库,相当于快捷方式。
import matplotlib.pyplot as plt
plt.plot([3,1,4,5,2])
plt.ylabel("Grade")
plt.savefig('test',dip=600) ##存储成PNG的格式,默认PNG格式,可以通过dip修改输出质量
plt.show()
import matplotlib.pyplot as plt
plt.plot([0,2,4,6,8],[3,1,4,5,2])##plt.plot(x,y)当由2各以上参数时,按照X轴和Y轴顺序绘制数据点。
plt.ylabel("Grade")
plt.axis([-1,10,0,6])##是X和Y轴的范围
plt.show()

pyplot的绘图区域:在全域绘图区域中创建一个分区体系,并定位到一个子绘图区域。

plt.subplot(nrows,ncols,plot_number)
plt.subplot(3,2,4)
plt.subplot(324)

在这里插入图片描述
举个栗子:

import numpy as np
import matplotlib.pyplot as plt 
def f(t):
    return np.exp(-t)*np.cos(2*np.pi*t)  ##定义一个能量衰减函数
a=np.arange(0.0,5.0,0.02)##随机生成一个数组a
plt.subplot(211)##将绘图区域分成2行一列,选择二第一个区域作图
plt.plot(a,f(a))
plt.subplot(2,1,2)
plt.plot(a,np.cos(2*np.pi*a),"r--")
plt.show()

在这里插入图片描述
plt.plot(x,y,format_string,kwargs)

  • x:x轴数据,列表或者数组,可选。
  • y:y轴数据,列表或数组。
  • format_string:控制曲线的格式字符串,可选。
  • kwargs:第二组或更多(x,y,format_string)
import matplotlib.pyplot as plt
import numpy as np
a=np.arange(10)
plt.plot(a,a*1.5,a,a*2.5,a,a*3.5,a,a*4.5) 
plt.show()

for

Unlock deeper insights into visualization in form of 2D and 3D graphs using Matplotlib 2.x About This BookCreate and customize live graphs, by adding style, color, font to make appealing graphs.A complete guide with insightful use cases and examples to perform data visualizations with Matplotlib's extensive toolkits.Create timestamp data visualizations on 2D and 3D graphs in form of plots, histogram, bar charts, scatterplots and more.Who This Book Is For This book is for anyone interested in data visualization, to get insights from big data with Python and Matplotlib 2.x. With this book you will be able to extend your knowledge and learn how to use python code in order to visualize your data with Matplotlib. Basic knowledge of Python is expected. What You Will LearnFamiliarize with the latest features in Matplotlib 2.xCreate data visualizations on 2D and 3D charts in the form of bar charts, bubble charts, heat maps, histograms, scatter plots, stacked area charts, swarm plots and many more.Make clear and appealing figures for scientific publications.Create interactive charts and animation.Extend the functionalities of Matplotlib with third-party packages, such as Basemap, GeoPandas, Mplot3d, Pandas, Scikit-learn, and Seaborn.Design intuitive infographics for effective storytelling.In Detail Big data analytics are driving innovations in scientific research, digital marketing, policy-making and much more. Matplotlib offers simple but powerful plotting interface, versatile plot types and robust customization.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值