tikzplotlib
tikzplotlib copied to clipboard
[feature request] layered graphics
trafficstars
Hello,
I want to reproduce the zorder effects as here. The Python code is pasted as follows:
import matplotlib.pyplot as plt
import numpy as np
# Fixing random state for reproducibility
np.random.seed(19680801)
x = np.random.random(20)
y = np.random.random(20)
plt.figure()
plt.subplot(211)
plt.plot(x, y, 'C3', lw=3)
plt.scatter(x, y, s=120)
plt.title('Lines on top of dots')
# Scatter plot on top of lines
plt.subplot(212)
plt.plot(x, y, 'C3', zorder=1, lw=3)
plt.scatter(x, y, s=120, zorder=2)
plt.title('Dots on top of lines')
plt.tight_layout()
import tikzplotlib
tikzplotlib.save('./nolayer.tikz')
The LaTeX code:
\documentclass{standalone}
%% tikz's stuff start
\usepackage{tikz, color, graphics, pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{dateplot}
\usetikzlibrary{patterns, arrows}
%% tikz's stuff end
\begin{document}
\input{./nolayer.tikz}
\end{document}
The expected result is

but tikzplotlib gave me

where dots are on top of lines in both subplots.
It turns out that the TikZ library does provide layering, therefore we can do a little fine-tuning on the generated .tikz file at this moment, but I think it could be better that tikzplotlib can do this for us in the future.
Thank you, Yanmao
For my own reference: There's this question on stackoverflow. The reply is not very satisfying though.
I just wrote Christian (the author of pgfplots), so let's see if we're getting proper zorder in pgfplots anytime soon.