python matplotlib生成图表基础

本节的目标是绘制一个y = x**2的函数图像

plot图表 绘制图表
plot()函数绘制图表,传入参数,输入值和输出值,还可以指定其他参数

plt.plot(input_values, squares, linewidth = 5)
要绘制单个点,可使用函数scatter() ,并向它传递一对 x 和 y 坐标,它将在指定位置绘制一个点
plt.scatter(2, 4, s=200)
传入xy坐标,s表示点的大小

```python
plt.axis([0,1100,0,1100000])
axis设置坐标,传入xy坐标最小值和最大值

matplotlib默认点是蓝色,轮廓是黑色,点太密集时黑色轮廓盖住蓝色点

import matplotlib.pyplot as plt

x_values = list(range(1,1001))
y_values = [x**2 for x in x_values]

# plt.plot(input_values, squares, linewidth = 5)
#设置图表线条粗细

plt.scatter(x_values, y_values, c ='red', edgecolor = 'none',s=40)
#标题xy坐标
plt.title("Squares Numbers", fontsize = 14)
plt.xlabel("Value",fontsize = 14)
plt.ylabel("Square of Value",fontsize = 14)
#axis坐标轴
#设置每个坐标轴的取值范围
plt.axis([0,1100,0,1100000])

plt.savefig('squares_plot.png',bbox_inches='tight')
# plt.show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值