thomas-saigre / tikzplotly

Export plotly figures as TikZ/PGFplots for integration in LaTeX
https://pypi.org/project/tikzplotly/
MIT License
18 stars 1 forks source link

Integer marker symbols cause a TypeError #16

Closed Viech closed 2 months ago

Viech commented 3 months ago

Plotting a figure with the trace

dict(
    mode="markers",
    x=coords[0],
    y=coords[1],
    marker=dict(
        symbol=0,
        size=10,
        line_width=2,
        line_color="#444",
        color=color,
    ),
)

leads to the exception

Traceback (most recent call last):
  File "…", line 228, in <module>
    tikzplotly.save(path, fig)
  File "…/.local/lib/python3.12/site-packages/tikzplotly/_save.py", line 123, in save
    code = get_tikz_code(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "…/.local/lib/python3.12/site-packages/tikzplotly/_save.py", line 59, in get_tikz_code
    data_str.append( draw_scatter2d(data_name_macro, trace, y_name, axis, colors_set) )
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "…/.local/lib/python3.12/site-packages/tikzplotly/_scatter.py", line 52, in draw_scatter2d
    symbol, symbol_options = marker_symbol_to_tex(marker.symbol)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "…/.local/lib/python3.12/site-packages/tikzplotly/_marker.py", line 119, in marker_symbol_to_tex
    if "-dot" in symbol:
       ^^^^^^^^^^^^^^^^
TypeError: argument of type 'int' is not iterable

Replacing symbol=0 with symbol="circle" works around this.

thomas-saigre commented 3 months ago

Indeed, I only implemented symbols that are given as a string, I shall fix this, thanks for spotting the error :)

For the record, here is an example of code leading to this error:

Code with the error ```py import plotly.express as px import tikzplotly df = px.data.iris() fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species") fig.update_traces(marker=dict(size=12, symbol = 0, line=dict(width=2, color='DarkSlateGrey')), selector=dict(mode='markers')) # fig.show() tikzplotly.save("test.tex", fig) ```