相关疑难解决方法(0)

为特定的 x 轴刻度设置不同的字体颜色

我正在创建一个频率图,其中也绘制了 NA 值。我试图在 x 轴刻度中以不同的方式为 N/A 值着色。我知道如何在 matplotlib 中做到这一点,但似乎无法弄清楚如何使用 plotly 来做到这一点。

我尝试使用值列表更新 tickcolors 和 tickfonts,但它只需要这两个属性的单个值。请看下面的代码

# Doesn't work - plotly expects a single value for tickcolor
fig.update_xaxes(
    tickangle = -60, 
    tickcolor = ['black', 'black', 'black', 'black', 'red']
)

# In matplotlib the following code works fine
# It checks the text for xticklabels and changes color if it equals 'N/A'

  _  = [xl.set_color('red') for xl in plt.gca().get_xticklabels() if xl.get_text() == 'N/A / Missing']


Run Code Online (Sandbox Code Playgroud)

我希望它看起来像这样 - 这是我的 matplotlib 代码预期输出的输出

python matplotlib plotly

3
推荐指数
1
解决办法
2165
查看次数

标签 统计

matplotlib ×1

plotly ×1

python ×1