python画图坐标轴保留一位小数_Python零基础之——绘制折线图、散点图!
Python绘图需要下载安装matplotlib模块,它是一个数学绘图库,我们将使用它来制作简单的图表,如折线图和散点图。关于matplotlib模块的下载安装预配置将在后面具体介绍。(一)绘制折线图首先,我们先绘制一个简单的折线图# 调用模块import matplotlib.pyplot as plt squares=[1, 4, 9, 16, 25]x=[1, 2, 3, 4, 5]plt.
·
Python绘图需要下载安装matplotlib模块,它是一个数学绘图库,我们将使用它来制作简单的图表,如折线图和散点图。关于matplotlib模块的下载安装预配置将在后面具体介绍。
(一)绘制折线图
首先,我们先绘制一个简单的折线图
# 调用模块import matplotlib.pyplot as plt squares=[1, 4, 9, 16, 25]x=[1, 2, 3, 4, 5]plt.plot(x, squares)plt.show()
解释:
(1)plt.plot(x, squares)作用是画图,其中x相当于横坐标轴,squaers相当于纵坐标轴;
(2)plt.show()作用是将画好的图显示出来。
接下来,对上图进行进一步的修饰。
import matplotlib.pyplot as pltsquares=[1, 4, 9, 16, 25]x=[1, 2, 3, 4, 5]# 设置线宽plt.plot(x, squares, linewidth=4)# 设置图表标题,并给坐标轴添加标签plt.title("square of 'x'
更多推荐



所有评论(0)