O Matplotlib reconhece código LaTeX sem maiores problemas para as legendas
O Plotly possui diversos problemas de interação com LaTeX
necessidade de ter o MathJax local ou via CDN
não tem comportamento muito previsível em hover ou em labels (ver refs abaixo)
Possíveis soluções:
função usando LaTeX para uso com Matplotlib e função usando HTML para Plotly conforme #4
:-1: repetição de lógica/código
:-1: não lida bem com cargas
delegar criação das fórmulas para a classe Substance do chempy
:+1: pode usar os métodos latex_name e html_name
:-1: mais uma dependência...
:+1: lida com a questão da representação correta das cargas: - ao invés de -1; 2- ao invés de -2
:-1: não lida bem índices 0 e 1: H_0A^- ao invés de A^- e H_1A ao invés de HA
pode ser contornado da mesma forma que é contornado nas funções atuais
:+1: pode ser uma única função, com um argumento onde se diz qual tipo de retorno é desejado
from chempy import Substance
...
def formulas(output='latex'):
...
if output == 'latex':
...
if output == 'html':
...
...
Tendo, no momento, a considerar a solução com o `chempy` melhor.
Referências para problemas do Plotly com LaTeX:
- https://togithub.com/plotly/plotly.js/issues/559
- https://community.plotly.com/t/hovertemplate-does-not-show-name-property/36139
- https://stackoverflow.com/questions/64718655/plotly-fails-to-show-text-in-latex-labels-in-python
- https://community.plotly.com/t/latex-text-does-not-work-at-all-in-plotly-offline/13800
- https://togithub.com/plotly/plotly.py/issues/515
- https://community.plotly.com/t/latex-in-layout-title-does-not-work-properly/21585
Possíveis soluções:
Substance
do chempylatex_name
ehtml_name
-
ao invés de-1
;2-
ao invés de-2
H_0A^-
ao invés deA^-
eH_1A
ao invés deHA
def formulas(output='latex'): ... if output == 'latex': ... if output == 'html': ... ...