Skip to content

Commit 1cf66a0

Browse files
authored
Merge pull request #221 from tino-michael/dark_colour
catching error during messy RGBA colour handling
2 parents 94aa071 + 5ec3f3e commit 1cf66a0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

matplotlib2tikz/legend.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,16 @@ def draw_legend(data, obj):
202202
# Set color of lines in legend
203203
for handle in obj.legendHandles:
204204
try:
205-
data, legend_color, _ = mycol.mpl_color2xcolor(data,
206-
handle.get_color())
205+
# when using matplotlib colours like "darkred" or "darkorange",
206+
# `handle.get_color` will create nested RGBA codes
207+
# e.g. `[[ 0.54509804, 0., 0., 1.]]` which casuse mpl to throw an error.
208+
# catch this error, `numpy.squeeze` the colour code and try again
209+
try:
210+
data, legend_color, _ = mycol.mpl_color2xcolor(
211+
data, handle.get_color())
212+
except ValueError:
213+
data, legend_color, _ = mycol.mpl_color2xcolor(
214+
data, numpy.squeeze(handle.get_color()))
207215
data['legend colors'].append('\\addlegendimage{no markers, %s}\n'
208216
% legend_color)
209217
except AttributeError:

0 commit comments

Comments
 (0)