Skip to content

Empty Drawcolor for scatterplot #66

Description

@Goregg

Describe the bug
When converting a seaborn scatterplot the output tikz file is broken because it tries the add a drawcolor for which there is no data.

To Reproduce
Steps to reproduce the behavior:

  • Python version: 3.12
  • Version matplot2tikz==0.5.3 and seaborn==0.13.2

The code producing the faulty tikz looks like this.
Sadly i cant share the data. I am also unsure if the subplot is relevant to the problem but wanted to leave it in for a fuller picture.

import seaborn as sns
from matplotlib import pyplot as plt
import matplot2tikz

n_rows = 2
n_cols = 2
fig, axs = plt.subplots(n_rows, n_cols)
axes = list(axs.flat)

datasets = ["a", "b", "c", "d"]

for ax, ds in zip(axes, datasets):
    sub = df[df["dataset"] == ds]

sns.scatterplot(
    x="varA",
    y="varB",
    hue="varC",
    data=sub,
    palette="Set2",
    alpha=0.5,
)

ax.set_xscale("log")

plt.tight_layout()

matplot2tikz.save(
    output_path,
    show_info=True,
    extra_groupstyle_parameters=[
        "vertical sep=1.5cm",
    ],
)

Then the output tikz files contains this bad code from which the drawcolor needs to be removed to achieve the working good code.
(this is only the short important part of the tikz file)

OLD BAD CODE

scatter/@pre marker code/.code={%
\expanded{%
\noexpand\definecolor{thispointdrawcolor}{RGB}{\drawcolor}%
\noexpand\definecolor{thispointfillcolor}{RGB}{\fillcolor}%
}%
\scope[draw=thispointdrawcolor, fill=thispointfillcolor]%
},
visualization depends on={value \thisrow{draw} \as \drawcolor},
visualization depends on={value \thisrow{fill} \as \fillcolor}

NEW GOOD CODE

scatter/@pre marker code/.code={%
\expanded{%
  \noexpand\definecolor{thispointfillcolor}{RGB}{\fillcolor}%
}%
\scope[fill=thispointfillcolor]%
},
visualization depends on={value \thisrow{fill} \as \fillcolor}

Expected behavior
It should output a working tikz file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions