0
A
回答
0
可以使用LineCollection
创建multicolored line。然后,您可以使用xaxis转换将其固定到x轴,而不受y限制的限制。将实际脊柱设置为不可见并关闭clip_on
使LineCollection看起来像轴脊柱。
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
import numpy as np
fig, ax = plt.subplots()
colors=["b","r","lightgreen","gold"]
x=[0,.25,.5,.75,1]
y=[0,0,0,0,0]
points = np.array([x, y]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lc = LineCollection(segments,colors=colors, linewidth=2,
transform=ax.get_xaxis_transform(), clip_on=False)
ax.add_collection(lc)
ax.spines["bottom"].set_visible(False)
ax.set_xticks(x)
plt.show()
相关问题
- 1. Matplotlib:多种颜色的y轴标签
- 2. matplotlib绘图中使用多种颜色
- 3. 使用2轴颜色表中matplotlib
- 4. Matplotlib:更改轴的颜色
- 5. 多种颜色
- 6. 集matplotlib的颜色刻度上我已成功使用设置脊柱,标签,数字和我的图形的刻度线的颜色日志缩放轴
- 7. 使用matplotlib的颜色循环作为颜色映射
- 8. 使用matplotlib绘制颜色条,区别颜色和不连续颜色
- 9. 使用多种文字颜色[Html.fromhtml()]
- 10. mollview:使用matplotlib颜色表并更改背景颜色
- 11. Matplotlib - 使用plt.setp不同的颜色()
- 12. 使用matplotlib的pcolormesh指定颜色
- 13. PatchCollection的Matplotlib颜色条替换颜色
- 14. 颜色绘制不同的颜色matplotlib
- 15. Matplotlib:三种颜色的自定义颜色图
- 16. TTTAttributedLabel多种颜色
- 17. 使用matplotlib颜色表与dataframe.plot功能
- 18. Matplotlib颜色映射:最大颜色数
- 19. 使用javascript检测颜色是否在两种颜色之间
- 20. matplotlib中的颜色
- 21. matplotlib正确的颜色/彩条与多面积每一种不同的颜色
- 22. 背景颜色50%一种颜色和50%另一种颜色
- 23. 两种不同颜色的colormaps matplotlib
- 24. 垂直使用2种颜色的UILabel
- 25. matplotlib图填充轴上方和下方的2种颜色
- 26. matplotlib facecolor多种颜色全部结果为黑色
- 27. pyqtgraph:PyQtGraph中的多种颜色
- 28. R:多种颜色的猫
- 29. TextBlock中的多种颜色
- 30. UILabel中的多种颜色
真棒。你能描述一下'transform = ax.get_xaxis_transform()'是做什么的?我似乎无法找到'transform'属性定义。 – JeeYem
您可能需要阅读[转换教程](http://matplotlib.org/users/transforms_tutorial.html)。每个艺术家都有变形属性。变换将坐标映射到画布。通常情况下,你不会太在意,因为你想使用数据坐标,而艺术家默认使用transData变换。在这种情况下,我们不希望根据数据坐标在y方向上确定线的位置,而是将其固定在坐标轴上。 'ax.get_xaxis_transform()'给出了一个转换,它需要数据单位中的x坐标和轴单位中的y坐标。 – ImportanceOfBeingErnest