标签:了解 label 散点图 简单的 pac 连接 模块 坐标轴 lin
from matplotlib import pyplot as plt import numpy as np # 从[0, 10]区间内,等分取出100个点(包含0和10); x = np.linspace(0, 10, 100) y = np.sin(x) # 绘制以x为横轴,y为纵轴,绘图,生成matplotlib.lines.Line2D对象 plt.plot(x, y) # 使用plt的show函数显示图线对象 plt.show()
from matplotlib import pyplot as plt import numpy as np x = np.linspace(0, 10, 100) siny = np.sin(x) cosy = np.cos(x) # 绘制多条曲线后再显示所有的线,才可以在同一个图内显示多条线 plt.plot(x, siny) plt.plot(x, cosy) plt.show()
plt.plot(x, siny) # 将cosy曲线的颜色调整为红色,线型为虚线 plt.plot(x, cosy, color = ‘red‘, linestyle = ‘--‘) # 分别限定横纵坐标范围:横轴在[5, 8],纵轴在[0, 1] plt.xlim(5, 8) plt.ylim(0, 1) # 也可以同时限定两个坐标轴的范围,默认两面两个参数为横坐标范围,后面两个参数为纵坐标范围 plt.axis([5, 8, 0, 1]) plt.show()
from matplotlib import pyplot as plt import numpy as np x = np.linspace(0, 10, 100) siny = np.sin(x) cosy = np.cos(x) # 添加图式:label plt.plot(x, siny, label = ‘sin(x)‘) plt.plot(x, cosy, color = ‘red‘, linestyle = ‘--‘, label = ‘cos(x)‘) # 添加横、纵左边的名称 plt.xlabel("x axis") plt.ylabel("y value") # 添加图表标题:title plt.title(‘Welcome to the Machine-Learn World‘) # 显示图式label plt.legend() plt.show()
from matplotlib import pyplot as plt import numpy as np x = np.linspace(0, 10, 100) siny = np.sin(x) cosy = np.cos(x) # 添加图式:label plt.scatter(x, siny) plt.scatter(x, cosy, color = "red") plt.show()
x = np.random.normal(0, 1, 10000) y = np.random.normal(0, 1, 10000) # 透明度设置为0.5 plt.scatter(x, y, alpha = 0.5)
机械学习:Jupyter Notebook中Matplotlib的使用
标签:了解 label 散点图 简单的 pac 连接 模块 坐标轴 lin
原文地址:https://www.cnblogs.com/volcao/p/9071530.html