tikzplotlib icon indicating copy to clipboard operation
tikzplotlib copied to clipboard

order of legend entries with 2 column format differs

Open JoTrab opened this issue 5 years ago • 0 comments
trafficstars

The order of entries for 2 column legends in a matplotlib plot is different from pgfplots. The first is top->bottom -> left ->right, while the second is top left -> top right -> 2nd top left ...... Any way to adapt this ? python Screenshot from 2020-09-14 12-45-31 pgf Screenshot from 2020-09-14 12-47-35

`plt.plot(fi[0],cV[0],alpha = 0.0,label = "Test title") plt.plot(fi[0],cV[0],alpha = 0.0,label = " ") plt.plot(cs1[:,0],cs1[:,1],'k-', alpha = 1.0, label='a') # healthy plt.plot(cs4[:,0],cs4[:,1],'c-', alpha = 1.0,label='b') plt.plot(cs2[:,0],cs2[:,1],'k-', alpha = 1.0,label='c') # healthy plt.plot(cs9[:,0],cs9[:,1],'r-', alpha = 1.0,label='d') plt.plot(cs3[:,0],cs3[:,1],'k-', alpha = 1.0, label='e') # healthy plt.plot(cs7[:,0],cs7[:,1],'b-', alpha = 1.0,label='f') plt.plot(cs8[:,0],cs8[:,1],'b-', alpha = 1.0,label='g')

a = plt.gca()

handles,labels = a.get_legend_handles_labels() #handles = a.lines #a.legend(handles, labels,loc=2,bbox_to_anchor=(1.0,1.0)) a.legend(handles, labels,ncol=2,loc=4,bbox_to_anchor=(1.0,1.0))

a.set_xlabel('f [Hz]') a.set_ylabel('c$_s$ [$\frac{m}{s}$]') a.set_xlim(0, 400) a.set_ylim(0,4) a.grid()

tikzplotlib.clean_figure()

tikz_save(SaveFigPath + 'LitDisp1.pgf',standalone=True)`

`\documentclass{standalone} \usepackage[utf8]{inputenc} \usepackage{pgfplots} \DeclareUnicodeCharacter{2212}{−} \usepgfplotslibrary{groupplots} \usepgfplotslibrary{dateplot} \usetikzlibrary{patterns} \usetikzlibrary{shapes.arrows} \pgfplotsset{compat=newest} \begin{document} % This file was created by tikzplotlib v0.9.1. \begin{tikzpicture}

\definecolor{color0}{rgb}{0.12156862745098,0.466666666666667,0.705882352941177} \definecolor{color1}{rgb}{1,0.498039215686275,0.0549019607843137} \definecolor{color2}{rgb}{0,0.75,0.75}

\begin{axis}[ legend cell align={left}, legend columns=2, legend style={fill opacity=0.8, draw opacity=1, text opacity=1, at={(1,1)}, anchor=south east, draw=white!80!black}, tick align=outside, tick pos=left, x grid style={white!69.0196078431373!black}, xlabel={x}, xmajorgrids, xmin=0, xmax=400, xtick style={color=black}, y grid style={white!69.0196078431373!black}, ylabel={y}, ymajorgrids, ymin=0, ymax=4, ytick style={color=black} ] \addplot [ultra thick, color0, opacity=0.0] table {% 0.1 0.97611878091489 }; \addlegendentry{Test title} \addplot [ultra thick, color1, opacity=0.0] table {% 0.1 0.97611878091489 }; \addlegendentry{ } \addplot [ultra thick, black, opacity=1.0] table {% 42.845 1.1263 43.273 1.1289 83.634 1.3648 84.065 1.3676 126.584 1.5128 127.442 1.5187 170.381 1.7343 170.812 1.7364 213.321 1.9815 213.323 1.9815 255.423 1.9987 255.424 1.9987 298.803 2.1435 298.804 2.1435 340.472 2.2064 340.473 2.2064 383.4 2.5434 383.83 2.5425 425.501 2.5871 425.93 2.5878 }; \addlegendentry{a} \addplot [ultra thick, color2, opacity=1.0] table {% 32.57 1.0937 62.07 1.3019 94.82 1.2912 125 1.2805 156.44 1.3493 187.9 1.3685 218.07 1.4274 250.17 1.4565 280.35 1.4358 312.43 1.5345 343.25 1.5736 374.7 1.6126 405.52 1.6218 436.97 1.6508 }; \addlegendentry{b} \addplot [ultra thick, black, opacity=1.0] table {% 85.13 1.2949 125.858 1.504 169.607 1.6308 212.046 1.8673 254.508 1.9942 298.673 2.185 340.288 2.2571 382.337 2.3109 424.765 2.593 }; \addlegendentry{c} \addplot [ultra thick, red, opacity=1.0] table {% 11.53 0.324 49.6 1.1274 90.54 1.7365 148.79 1.9136 185.7 1.9352 208.19 2.0864 239.91 2.2635 271.05 2.1728 308.54 2.2376 347.17 2.4665 385.81 2.5572 411.19 2.5832 419.26 4.0734 450.98 3.7797 461.94 2.6955 497.12 2.5875 }; \addlegendentry{d} \addplot [ultra thick, black, opacity=1.0] table {% 84.37 1.6751 126.829 1.9497 169.738 2.0412 212.631 2.2792 254.246 2.4256 298.443 2.508 340.938 2.4622 382.528 2.8375 425.426 3.0297 }; \addlegendentry{e} \addplot [ultra thick, blue, opacity=1.0] table {% 60.179 0.9828 89.719 1.0955 119.255 1.21186 148.542 1.3197 178.373 1.40928 207.936 1.50494 238.29 1.59329 268.088 1.70843 }; \addlegendentry{f} \addplot [ultra thick, blue, opacity=1.0] table {% 62.287 1.24215 90.423 1.34081 120.769 1.43498 150.484 1.53363 181.148 1.63677 210.547 1.73094 240.262 1.8296 270.609 1.92825 300.326 2.03139 331.939 2.13901 361.02 2.2287 390.108 2.34081 }; \addlegendentry{g} \end{axis}

\end{tikzpicture}

\end{document} `

JoTrab avatar Sep 14 '20 10:09 JoTrab