# 07.Matplotlib可视化

matplotlib是一个python 2D绘图库,利用它可以画出许多高质量的图像。只需几行代码即可生成直方图,条形图,饼图,散点图等。

Matplotlib可用于Python脚本,Python和IPython shell,Jupyter笔记本,Web应用程序服务器和四个图形用户界面工具包。希望本文能帮助大家了解如何将matplotlib用于自己的可视化。

文档参考:

  1. 十分钟|matplotlib上手,开启你的python可视化 (opens new window)
  2. Matplotlib 官方手册 (opens new window)

# Example

import numpy as np
import matplotlib.pyplot as plt
 
x = np.arange(0, 6, 0.1)
y = np.sin(x)
 
plt.plot(x,y)
plt.show()
1
2
3
4
5
6
7
8

image

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

fruits = ['apple', 'blueberry', 'cherry', 'orange']
counts = [40, 100, 30, 55]
bar_labels = ['red', 'blue', '_red', 'orange']
bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']

ax.bar(fruits, counts, label=bar_labels, color=bar_colors)

ax.set_ylabel('fruit supply')
ax.set_title('Fruit supply by kind and color')
ax.legend(title='Fruit color')

plt.show()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

image

Last Updated: 2/7/2024, 11:53:07 AM
Apache License 2.0 | Copyright © 2022 by xueliang.wu 苏ICP备15016087号