Skip to content

problem with colorbar LaTeX title rendering #2231

Open
@remingtonsexton

Description

@remingtonsexton

I am trying to implement a LaTeX math title for my colorbar and plotly is having some trouble rendering it. I am using Python 2.7, Plotly 4.5.2. My code:

fig = go.Figure()
fig.add_trace(go.Scatter(x=x_data, 
                         y=y_data,
                         mode='markers',text=obj_name,name='',
                         marker=dict(symbol='circle',size=12,line=dict(width=1,color='SlateGray'),
                                     opacity=0.75,color=log_mbh,colorscale='Rainbow',showscale=True,
                                     cmin=6.0,cmax=8.0,
                                     colorbar=dict(title=dict(text=r'$\Large\alpha\beta\gamma\delta$',side='top'),
                                                   thickness=50,tickmode='array',tickvals=[6.0,6.5,7.0,7.5,8.0]), 
                                    ),
                         )
             )
fig.add_trace(go.Scatter(x=np.arange(0,300,10), y=np.arange(0,300,10),
                         line = dict(color='LightSlateGray', width=2, dash='dash')))

fig.update_layout(
    template='plotly_white',
    xaxis = dict(showgrid=False,ticks='inside',zeroline=True,zerolinecolor='black',rangemode='tozero'),
    yaxis = dict(showgrid=False,ticks='inside',zeroline=True,zerolinecolor='black',rangemode='tozero'),
    xaxis_title=dict(text=r'$x$'),
    yaxis_title=dict(text=r'$y$'),
    font=dict(size=16),
    showlegend = False,
    autosize   = False,
    width      = 750,
    height     = 750,
    margin     = dict(l=50,r=50,b=50,t=50,pad=10),
)

fig.show()

Which produces the output:

newplot (1)

As you can see, the LaTeX title seems to be rotated 90 deg, and ignoring side='top'. I have tried to increase the width of the colorbar and increase the plot's margins to no avail. Is there a workaround or solution for this problem?

Activity

remingtonsexton

remingtonsexton commented on Feb 27, 2020

@remingtonsexton
Author

Update: I have found a workaround but not a solution. This is definitely a bug as far as I cant tell.

One option, if you do not require Greek alphabet, is to simply use HTML code, simply using italics, superscripts or subscripts.

If one wants to use Greek letters, HTML entities don't work, but a few decimal and hexadecimal codes do work.

This issue should be addressed, especially if Plotly is to be used for publishing purposes. Otherwise, Matplotlib is the alternative that does work.

theo-brown

theo-brown commented on Nov 1, 2022

@theo-brown

Any updates?

Allyson-Robert

Allyson-Robert commented on Mar 11, 2023

@Allyson-Robert

At the risk of repeating the previous poster: Are there any updates on this or any way to work around the issue in another way? I use LaTeX extensively and it would require a complete rewrite to switch

nicolaskruchten

nicolaskruchten commented on Mar 11, 2023

@nicolaskruchten
Contributor

No updates or workarounds, sorry, this is just currently unsupported and as far as I know no one is working on this issue. The fix would need to be implemented in Plotly.js: plotly/plotly.js#4605

Allyson-Robert

Allyson-Robert commented on Mar 11, 2023

@Allyson-Robert

No updates or workarounds, sorry, this is just currently unsupported and as far as I know no one is working on this issue. The fix would need to be implemented in Plotly.js: plotly/plotly.js#4605

Thanks for the reply. It really is unfortunate. I wish I had the skills to fix this myself

empet

empet commented on Mar 11, 2023

@empet

To add a LaTeX title to colorbar I'm working with PlotlyJS.jl, a Julia lang version of plotly.
In Jupyter Notebook with Julia kernel all greek letters, subscripts, superscripts and more can be converted from Latex symbol to their unicode. As example, \xi followed by tab generates the corresponding letter ξ, then \_1 tab leads to ξ₁. Copy this string "ξ₁", and paste it after colorbar_title:

using PlotlyJS
fig = Plot(heatmap(z=rand(5, 5), colorbar_title="ξ₁/μ", colorbar_thickness=23),
           Layout(width=400, height=370))

Latex-colorbar

Depending on your colorbar title, it is also possible to generate the unicode of a LateX symbol in a Jupyter Notebook with Python kernel. You can get all greek letters similarly: Latex and tab.
Another workaround is to search the web for the unicode of your LaTeX symbol.
For example replacing in both Julia and Python code, the above string assigned to colorbar_title, with colorbar_title="A\u2229B" we get:
Latex-colorbar2

f0uriest

f0uriest commented on Sep 20, 2023

@f0uriest

Not an ideal fix, but converting the TeX to unicode with https://github.com/phfaist/pylatexenc worked for me.

self-assigned this
on Jul 8, 2024
removed their assignment
on Aug 2, 2024
changed the title [-]Colorbar LaTeX Title Rendering[/-] [+]problem with colorbar LaTeX title rendering[/+] on Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nicolaskruchten@gvwilson@empet@theo-brown@f0uriest

        Issue actions

          problem with colorbar LaTeX title rendering · Issue #2231 · plotly/plotly.py