python - 使用 seaborn/matplotlib 将直线图变成曲线图
问题描述
我想知道是否有人知道如何使用 matplotlib 或 seaborn 来弯曲原来的直线?原因是我有很多线从 A 点到 B 点。
我在这里附上了一个具体的例子。我从 A 点到 B 点有三条线。如果不弯曲其中两条,我将无法分辨出有三条线(第一个图)。只有弯曲两条线,你才能知道实际上有三条线从 A 到 B (第二个图;我手动添加了曲线)。
解决方案
我认为“弯曲”这条线并实际制作虚假数据没有任何意义。但是给你:
import matplotlib.patches as patches
import matplotlib.pyplot as plt
plt.close()
fig, ax = plt.subplots()
x = np.arange(50)
y = np.arange(50)
ax.plot(x, y)
a_red = patches.FancyArrowPatch((x[0], y[0]), (x[-1], y[-1]), connectionstyle="arc3,rad=0.1", arrowstyle="Simple, tail_width=0.5, head_width=4, head_length=8", color='r')
a_gre = patches.FancyArrowPatch((x[0], y[0]), (x[-1], y[-1]), connectionstyle="arc3,rad=-0.1", arrowstyle="Simple, tail_width=0.5, head_width=4, head_length=8", color='g')
plt.gca().add_patch(a_red)
plt.gca().add_patch(a_gre)
输出:
推荐阅读
- wordpress - 使用 APIResponse 更新 WooCommerce 结帐字段
- ios - Xcode SwiftUI PayPal 集成 iOS
- python - 乳胶错误!FileNotFoundError:[Errno 2] 没有这样的文件或目录:'C:\\Users\\Diego\\AppData\\Local\\Temp\\Tex\\7f1e3ce1a2acebb7.log'
- javascript - 更改与#anchor 匹配的链接的CSS
- c# - LDAP DirectoryEntry 获取特定的计算机属性
- javascript - 打字稿工具
- android - ListView 中的多个秒表计时器在删除/添加时重置
- c++ - 从基类调用派生类中的函数
- date - Kotlin - 无法解析的日期:“2021-07-20T12:35:07-07:00”
- react-native - 如何在 React Native 导航器材质顶部选项卡中实现渐变指示器?