如何使用 plotly Express 添加第二个 Y 轴?

时间:2021-05-16 16:03:50

标签: python plotly plotly-express

首先我将向您展示代码。我在收集数据方面没有问题,但更多的是以正确的方式呈现它们。

import numpy as np 

rows = np.r_['1,2,0', :6, :6]
mask = np.tile([1, 1, 0, 0, 1, 1], (2,1)).T.astype(bool)

def maskforwardfill(a: np.ndarray, mask: np.ndarray):
    mask = mask.copy()
    indices = np.arange(len(a))
    mask[np.diff(mask,prepend=[0]) == 1] = False # set leading True to False
    indices[mask] = -1 
    indices = np.maximum.accumulate(indices) # forward fill indices
    indices = np.unique(indices) # remove repeats
    return a[indices] # index out wanted rows

# Reduce mask's dimension since I assume that you only do complete rows
print(maskforwardfill(rows, mask.any(1)))
#[[0 0]
# [2 2]
# [3 3]
# [4 4]]

创建的图仅显示 Y 轴上的提及次数。我想找到一种方法来获得代表股票价格的第二个 Y 轴。 有人知道解决我的问题的方法吗?

1 个答案:

答案 0 :(得分:1)

我可能错了——但这似乎是个坏主意..

两轴图表真的很容易受到程序员部分的偏见的影响,对于很多人来说很难阅读 杂乱的东西让你更难分辨 趋势、模式 并了解图表的主题和故事。

这是一个例子 http://www.tylervigen.com/spurious-correlations

他使用这些图表制作了听起来很荒谬的疯狂关联。 是的,故意的 还有这个博客


这提供了很多很好的解决方案来思考 他们也有这个有点烦人的视频 解释他们反对 2 个轴的原因 它支持 但它长篇大论。这里https://blog.datawrapper.de/dualaxis/