matplotlib安装及使用

  1. matplotlib的安装                                                                                                                                                                                                                                                                                                                                     我使用的是pycharm开发,直接在.py文件里导入import matplotlib,如果报错则证明没有安装,点击修成错误,pycharm会自动帮我们安装
  2. 绘制简单的折线图  
import matplotlib.pyplot as plt


squares = [1, 4, 9, 16, 34]
plt.plot(squares)
plt.show()

  3. 校正图形

import matplotlib.pyplot as plt

input_values = [1, 2, 3, 4, 5]
squares = [1, 4, 9, 16, 25]
plt.plot(input_values, squares, linewidth=5)  # linewidth决定了线条的粗细

# 设置图表标题,并给坐标轴加上标签
plt.title('Square Numbers', fontsize=24)
plt.xlabel("Value", fontsize=14)
plt.ylabel('Square of value', fontsize=14)
plt.show()

# 设置刻度标记的大小
plt.tick_params(axis='both', labelsize=14)

  

猜你喜欢

转载自www.cnblogs.com/endian11/p/9070940.html