matplotlib绘图案例大全

2023-08-06  本文已影响0人  硅谷干货

Matplotlib 作为 Python 家族当中最为著名的画图工具,基本的操作还是要掌握的,文章很长,首先看下文章目录:

1、启用和检查交互模式

import matplotlib as mpl
import matplotlib.pyplot as plt
 
# Set the interactive mode to ON
plt.ion()
 
# Check the current status of interactive mode
print(mpl.is_interactive())

2、在 Matplotlib 中绘制折线图

import matplotlib.pyplot as plt

#Plot a line graph
plt.plot([5, 15])

# Add labels and title
plt.title("Interactive Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()

3、绘制带有标签和图例的多条线的折线图

import matplotlib.pyplot as plt

#Plot a line graph
plt.plot([5, 15], label='Rice')
plt.plot([3, 6], label='Oil')
plt.plot([8.0010, 14.2], label='Wheat')
plt.plot([1.95412, 6.98547, 5.41411, 5.99, 7.9999], label='Coffee')

# Add labels and title
plt.title("Interactive Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")

plt.legend()
plt.show()

4、在 Matplotlib 中绘制带有标记的折线图

import matplotlib.pyplot as plt
 
# Changing default values for parameters individually
plt.rc('lines', linewidth=2, linestyle='-', marker='*')
plt.rcParams['lines.markersize'] = 25
plt.rcParams['font.size'] = '10.0'
 
#Plot a line graph
plt.plot([10, 20, 30, 40, 50])
# Add labels and title
plt.title("Interactive Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
 
plt.show()

参考资料:
65 个 Matplotlib 案例
Matplotlib可视化

官网资料

上一篇 下一篇

猜你喜欢

热点阅读