python导入画图
时间: 2023-11-01 18:08:34 浏览: 95
Python导入画图的方法可以使用matplotlib库来实现。通常需要导入numpy、pandas和matplotlib.pyplot三个库。
对于列表数据画散点图的方法如下:
```python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
height = [168,150,200,190,185,100,125,180]
weight = [60,65,73,70,65,58,66,67]
plt.figure(figsize=(8, 4))
plt.scatter(height, weight,color='red',marker=' ')
plt.title('beauty')
plt.xlabel('weight')
plt.ylabel('height')
plt.show()
```
对于列表数据画连线图的方法如下:
```python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
age = [5, 10, 15, 20, 25, 30]
high = [60,100,150,170,171,171]
plt.figure(figsize=(8,4))
plt.plot(age)
plt.plot(age, high)
plt.grid(True)
plt.title('Age vs High')
plt.xlabel('age')
plt.ylabel('high')
plt.show()
```
对于数组数据画散点图的方法如下:
```python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
height = np.array([168,150,200,190,185,100,125,180])
weight = np.array([60,65,73,70,65,58,66,67])
plt.figure(figsize=(8, 4))
plt.scatter(height, weight)
plt.title('beauty')
plt.xlabel('weight')
plt.ylabel('height')
plt.show()
```
阅读全文