You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When combining an image with plt.imshow() and lines with plt.plot(), the legend is off.
Code to produce a axis with an imshow image as well as lineplots (only one marker printed for brevity):
importmatplotlib.pyplotaspltimporttikzplotlibplt.imshow([[1,2],[3,4]]) # no change in outcome if label was also set hereplt.plot(0,0,'x',label='0')
plt.plot(0,1,'x',label='1')
plt.plot(1,0,'x',label='2')
plt.plot(1,1,'x',label='3')
plt.legend()
plt.savefig('test_legend_imshow.png')
tikzplotlib.save('test_legend_imshow.tex',standalone=True, encoding='utf-8')
Resulting tex code:
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=newest}
\DeclareUnicodeCharacter{2212}{−}
\begin{document}
% This file was created by tikzplotlib v0.8.7.\begin{tikzpicture}
\definecolor{color0}{rgb}{0.12156862745098,0.466666666666667,0.705882352941177}
\definecolor{color1}{rgb}{1,0.498039215686275,0.0549019607843137}
\definecolor{color2}{rgb}{0.172549019607843,0.627450980392157,0.172549019607843}
\definecolor{color3}{rgb}{0.83921568627451,0.152941176470588,0.156862745098039}
\begin{axis}[
legend cell align={left},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, draw=white!80.0!black},
tick align=outside,
tick pos=left,
x grid style={white!69.01960784313725!black},
xmin=-0.5, xmax=1.5,
xtick style={color=black},
y dir=reverse,
y grid style={white!69.01960784313725!black},
ymin=-0.5, ymax=1.5,
ytick style={color=black}
]
\addplot graphics [includegraphics cmd=\pgfimage,xmin=-0.5, xmax=1.5, ymin=1.5, ymax=-0.5] {test_legend_imshow-000.png};
\addplot [semithick, color0, mark=x, mark size=3, mark options={solid}, only marks]
table {%
0 0
};
\addlegendentry{0}
\addplot [semithick, color1, mark=x, mark size=3, mark options={solid}, only marks]
table {%
0 1
};
\addlegendentry{1}
\addplot [semithick, color2, mark=x, mark size=3, mark options={solid}, only marks]
table {%
1 0
};
\addlegendentry{2}
\addplot [semithick, color3, mark=x, mark size=3, mark options={solid}, only marks]
table {%
1 1
};
\addlegendentry{3}
\end{axis}
\end{tikzpicture}
\end{document}
Expected output from plt.savefig:
Output after compiling pdf with pdflatex and pgfplots 1.16
The labels in the legend are correct, but the icon is shifted by one entry.
The text was updated successfully, but these errors were encountered:
When combining an image with
plt.imshow()
and lines withplt.plot()
, the legend is off.Code to produce a axis with an imshow image as well as lineplots (only one marker printed for brevity):
Resulting tex code:
Expected output from
![test_legend_imshow](https://user-images.githubusercontent.com/3519989/71724196-b5ffc400-2e2f-11ea-94b0-e69416898b90.png)
![test_legend_imshow pdf](https://user-images.githubusercontent.com/3519989/71724329-3b837400-2e30-11ea-9e6d-769214adb15f.png)
plt.savefig
:Output after compiling pdf with pdflatex and pgfplots 1.16
The labels in the legend are correct, but the icon is shifted by one entry.
The text was updated successfully, but these errors were encountered: