用Python画一个手绘风格的图
时间: 2024-04-10 10:09:10 浏览: 147
可以使用Python的Matplotlib库来画手绘风格的图。你可以使用sketch库给图形添加手绘笔触效果。以下是一个简单的示例代码:
```
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import sketch
# Generate sample data
x = np.linspace(0, 2 * np.pi, 100)
y1 = np.sin(x)
y2 = np.cos(x)
# Create figure and axes
fig, axs = plt.subplots(figsize=(8, 6), tight_layout=True)
# Add sketch effect to axes
sketch.add_axis_sketch(axs)
# Create grid spec for two subplots
gs = gridspec.GridSpec(2, 1)
# Add first subplot and plot data
ax1 = fig.add_subplot(gs[0])
ax1.plot(x, y1)
ax1.set_ylabel('Sin')
# Add second subplot and plot data
ax2 = fig.add_subplot(gs[1])
ax2.plot(x, y2)
ax2.set_ylabel('Cos')
ax2.set_xlabel('X')
# Show figure
plt.show()
```
这个代码会生成一个包含两个 subplot 的手绘风格图表,其中包含一条正弦函数和一条余弦函数的曲线。
阅读全文
相关推荐

















