<bdo id='yX18O'></bdo><ul id='yX18O'></ul>

        <small id='yX18O'></small><noframes id='yX18O'>

        <tfoot id='yX18O'></tfoot>

        <i id='yX18O'><tr id='yX18O'><dt id='yX18O'><q id='yX18O'><span id='yX18O'><b id='yX18O'><form id='yX18O'><ins id='yX18O'></ins><ul id='yX18O'></ul><sub id='yX18O'></sub></form><legend id='yX18O'></legend><bdo id='yX18O'><pre id='yX18O'><center id='yX18O'></center></pre></bdo></b><th id='yX18O'></th></span></q></dt></tr></i><div id='yX18O'><tfoot id='yX18O'></tfoot><dl id='yX18O'><fieldset id='yX18O'></fieldset></dl></div>

        <legend id='yX18O'><style id='yX18O'><dir id='yX18O'><q id='yX18O'></q></dir></style></legend>

        如何在情节中为ticktext着色?

        How to color ticktext in plotly?(如何在情节中为ticktext着色?)
          <tbody id='WbIQB'></tbody>

          1. <i id='WbIQB'><tr id='WbIQB'><dt id='WbIQB'><q id='WbIQB'><span id='WbIQB'><b id='WbIQB'><form id='WbIQB'><ins id='WbIQB'></ins><ul id='WbIQB'></ul><sub id='WbIQB'></sub></form><legend id='WbIQB'></legend><bdo id='WbIQB'><pre id='WbIQB'><center id='WbIQB'></center></pre></bdo></b><th id='WbIQB'></th></span></q></dt></tr></i><div id='WbIQB'><tfoot id='WbIQB'></tfoot><dl id='WbIQB'><fieldset id='WbIQB'></fieldset></dl></div>

            • <legend id='WbIQB'><style id='WbIQB'><dir id='WbIQB'><q id='WbIQB'></q></dir></style></legend>

                  <bdo id='WbIQB'></bdo><ul id='WbIQB'></ul>
                  <tfoot id='WbIQB'></tfoot>
                • <small id='WbIQB'></small><noframes id='WbIQB'>

                  本文介绍了如何在情节中为ticktext着色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想根据各自的字符串(基于字典)在我的 plotly xaxis 中以不同的颜色显示我的 ticktexts.plotly 中是否有功能可以做到这一点,也许是通过 HTML 编码?

                   ticktext = ['<font color="red">{}</font>'.format(x) for x in ticktexts]

                  不起作用,它将 html 字符串提供给标签.

                  解决方案

                  使用 LaTeX 的一点解决方法可以帮助你(对不起@Iwileczek,我偷了你的例子,希望你不要'不介意)因为 plotly 有完整的 LaTeX


                  2021 年 3 月更新:

                  如果您不想在输出中使用 MathJax 渲染的 LaTex 字体,请使用带有 HTML 样式的@Dapcer 的解决方案:

                  def color(color, text):return f"<span style='color:{str(color)}'>{str(text)} </span>>

                  fig.update_layout(font=dict(family="Times New Roman") [...] 的示例:

                  I would like to display my ticktexts in my plotly xaxis with different colors based on the respective string (based on a dictionary). Is there a functionality in plotly to do this, maybe via HTML coding?

                   ticktext = ['<font color="red">{}</font> '.format(x) for x in ticktexts]
                  

                  doesn't work, it gives the html string to the labels.

                  解决方案

                  A little bit of a workaround using LaTeX can help you here (sorry @Iwileczek, I stole your example, hope you don't mind) because plotly has full LaTeX support:

                  def color(color, text):
                      s = '$color{' + str(color) + '}{' + str(text) + '}$'
                      return s
                  
                  animals=['giraffes', 'orangutans', 'monkeys']
                  
                  colors = ['red', 'green', 'yellow', 'blue']
                  ticks = [5, 10, 15, 20]
                  keys = dict(zip(ticks, colors))
                  
                  fig = go.Figure([go.Bar(x=animals, y=[20, 14, 23])])
                  ticktext = [color(v, k) for k, v in keys.items()]
                  print(ticktext)
                  fig.update_layout(
                  yaxis=dict(tickmode='array', ticktext=ticktext, tickvals=ticks)
                  )
                  fig.show()
                  


                  Update March 2021:

                  If you don't want to use the LaTex rendered font by MathJax in your output, use the solution of @Dapcer with an HTML styling:

                  def color(color, text):
                      return f"<span style='color:{str(color)}'> {str(text)} </span>"
                  

                  Example with fig.update_layout(font=dict(family="Times New Roman") [...]:

                  这篇关于如何在情节中为ticktext着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                    <tfoot id='hopyh'></tfoot>

                    <legend id='hopyh'><style id='hopyh'><dir id='hopyh'><q id='hopyh'></q></dir></style></legend>
                        • <bdo id='hopyh'></bdo><ul id='hopyh'></ul>
                          <i id='hopyh'><tr id='hopyh'><dt id='hopyh'><q id='hopyh'><span id='hopyh'><b id='hopyh'><form id='hopyh'><ins id='hopyh'></ins><ul id='hopyh'></ul><sub id='hopyh'></sub></form><legend id='hopyh'></legend><bdo id='hopyh'><pre id='hopyh'><center id='hopyh'></center></pre></bdo></b><th id='hopyh'></th></span></q></dt></tr></i><div id='hopyh'><tfoot id='hopyh'></tfoot><dl id='hopyh'><fieldset id='hopyh'></fieldset></dl></div>
                            <tbody id='hopyh'></tbody>

                            <small id='hopyh'></small><noframes id='hopyh'>