python3实现绘制二维点图
时间:2021-09-25 08:18:00|栏目:Python代码|点击: 次
如下所示:
import matplotlib.pyplot as plt plt.plot([1,2,3],[4,5,6],'ro') plt.show()#这个智障的编辑器,,,看来高版本的确修复了一些bug
用python3的qt5出来的图形,效果很好:

而且在上面的图像中也可以用调整按钮进行适当的调整。
下面我们直接用代码进行坐标的调整:
import matplotlib.pyplot as plt plt.xlim(xmax=7,xmin=0) plt.ylim(ymax=7,ymin=0) plt.plot([1,2,3],[4,5,6],'ro') plt.show()

下面加一个标题,叫做散点图
import matplotlib.pyplot as plt
plt.title("I'm a scatter diagram.")
plt.xlim(xmax=7,xmin=0)
plt.ylim(ymax=7,ymin=0)
plt.plot([1,2,3],[4,5,6],'ro')
plt.show()

给xy轴进行命名
import matplotlib.pyplot as plt
plt.title("I'm a scatter diagram.")
plt.xlim(xmax=7,xmin=0)
plt.ylim(ymax=7,ymin=0)
plt.xlabel("x")
plt.ylabel("y")
plt.plot([1,2,3],[4,5,6],'ro')
plt.show()

加一个标注:
import matplotlib.pyplot as plt
plt.title("I'm a scatter diagram.")
plt.xlim(xmax=7,xmin=0)
plt.ylim(ymax=7,ymin=0)
plt.annotate("(3,6)", xy = (3, 6), xytext = (4, 5), arrowprops = dict(facecolor = 'black', shrink = 0.1))
plt.xlabel("x")
plt.ylabel("y")
plt.plot([1,2,3],[4,5,6],'ro')
plt.show()

多画几个图:
import matplotlib.pyplot as plt
plt.subplot(221)
plt.xlim(xmax=7,xmin=0)
plt.ylim(ymax=7,ymin=0)
plt.xlabel("x")
plt.ylabel("y")
plt.plot([1,2,3],[4,5,6],'ro')
plt.subplot(222)
plt.xlim(xmax=7,xmin=0)
plt.ylim(ymax=7,ymin=0)
plt.xlabel("x")
plt.ylabel("y")
plt.plot([1,2,3],[4,5,6],'ro')
plt.subplot(223)
plt.xlim(xmax=7,xmin=0)
plt.ylim(ymax=7,ymin=0)
plt.xlabel("x")
plt.ylabel("y")
plt.plot([1,2,3],[4,5,6],'ro')
plt.show()

上一篇:Jupyter加载文件的实现方法
栏 目:Python代码
下一篇:Python定时器实例代码
本文标题:python3实现绘制二维点图
本文地址:http://www.codeinn.net/misctech/177272.html






