[英]Is there a way to apply this function onto an Altair scatter plot?
I am hoping I can apply this draw_vector function onto an Altair scatter plot rather than matplotlib.我希望我可以将此 draw_vector 函数应用于 Altair 散点图而不是 matplotlib。 I am having trouble with a workaround.我在解决方法时遇到了麻烦。 Your expertise would be appreciated!您的专业知识将不胜感激!
def draw_vector(v0, v1, ax=None):
ax = ax or plt.gca()
arrowprops=dict(arrowstyle='->',
linewidth=2,
shrinkA=0, shrinkB=0)
ax.annotate('', v1, v0, arrowprops=arrowprops)
# plot data
plt.scatter(X[:, 0], X[:, 1], alpha=0.2)
for length, vector in zip(pca.explained_variance_, pca.components_):
v = vector * 3 * np.sqrt(length)
draw_vector(pca.mean_, pca.mean_ + v)
plt.axis('equal');
Here is what the above code produces for reference:以下是上述代码生成的内容以供参考:
I recognize that chart 😀我认得这张图表😀
Unfortunately, there is not really any support for arrows in Vega-Lite, the rendering library that Altair is built on, and so there is not really any great solution for rendering arrows with Altair.不幸的是,在 Altair 所基于的渲染库 Vega-Lite 中实际上并没有对箭头的任何支持,因此使用 Altair 渲染箭头并没有真正好的解决方案。 You can see a few workarounds in the tracking issue for this feature: https://github.com/altair-viz/altair/issues/914您可以在此功能的跟踪问题中看到一些解决方法: https ://github.com/altair-viz/altair/issues/914
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.