From 8cefb6974cfb2d2c28538c6e8872d889ea5c5a09 Mon Sep 17 00:00:00 2001 From: Jason Gross Date: Mon, 29 Apr 2024 20:50:09 -0700 Subject: [PATCH] Don't emit code for draw if the column doesn't exist --- src/tikzplotlib/_path.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/tikzplotlib/_path.py b/src/tikzplotlib/_path.py index 11381d59..d043bb70 100644 --- a/src/tikzplotlib/_path.py +++ b/src/tikzplotlib/_path.py @@ -194,21 +194,25 @@ def draw_pathcollection(data, obj): ls = None if add_individual_color_code: - draw_options.extend( - [ - "scatter", - "visualization depends on={value \\thisrow{draw} \\as \\drawcolor}", - "visualization depends on={value \\thisrow{fill} \\as \\fillcolor}", - "scatter/@pre marker code/.code={%\n" - + " \\expanded{%\n" - + " \\noexpand\\definecolor{thispointdrawcolor}{RGB}{\\drawcolor}%\n" - + " \\noexpand\\definecolor{thispointfillcolor}{RGB}{\\fillcolor}%\n" - + " }%\n" - + " \\scope[draw=thispointdrawcolor, fill=thispointfillcolor]%\n" - + "}", - "scatter/@post marker code/.code={%\n \\endscope\n}", - ] - ) + draw_options.append("scatter") + if "draw" in labels or "fill" in labels: + if "draw" in labels: + draw_options.append("visualization depends on={value \\thisrow{draw} \\as \\drawcolor}") + if "fill" in labels: + draw_options.append("visualization depends on={value \\thisrow{fill} \\as \\fillcolor}") + scope_vars = ", ".join(f"{var}=thispoint{var}color" for var in ("draw", "fill") if var in labels) + draw_options.extend( + [ + "scatter/@pre marker code/.code={%\n" + + " \\expanded{%\n" + + (" \\noexpand\\definecolor{thispointdrawcolor}{RGB}{\\drawcolor}%\n" if "draw" in labels else "") + + (" \\noexpand\\definecolor{thispointfillcolor}{RGB}{\\fillcolor}%\n" if "fill" in labels else "") + + " }%\n" + + " \\scope[" + scope_vars + "]%\n" + + "}", + "scatter/@post marker code/.code={%\n \\endscope\n}", + ] + ) # "solution" from #