Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Hiding tick marks also removes the tick labels #319

Open
ghost opened this issue Aug 2, 2019 · 0 comments
Open

Hiding tick marks also removes the tick labels #319

ghost opened this issue Aug 2, 2019 · 0 comments

Comments

@ghost
Copy link

ghost commented Aug 2, 2019

Hi, (and thanks for an awesome package!)

I think tikzplotlib is not working properly when you hide the tick marks (but not the labels) in your plot. If the ticks are hidden by using e.g. plt.rcParams.update({'xtick.bottom': False}), the ticks and tick labels are hidden in the resulting pgfplot.

My Python code (the README example modified):

import matplotlib.pyplot as plt
import numpy as np

plt.style.use("ggplot")

plt.rcParams.update({'xtick.bottom': False})  # Hide bottom ticks

t = np.arange(0.0, 2.0, 0.1)
s = np.sin(2 * np.pi * t)
s2 = np.cos(2 * np.pi * t)
plt.plot(t, s, "o-", lw=4.1)
plt.plot(t, s2, "o-", lw=4.1)
plt.xlabel("time (s)")
plt.ylabel("Voltage (mV)")
plt.title("Simple plot $\\frac{\\alpha}{2}$")
plt.grid(True)

import tikzplotlib

tikzplotlib.save("test.tex")

I get a nice figure with the bottom (x-axis) ticks removed (cf. the figure in the README):

image

But, when I typeset that with PdfLaTeX also the tick labels disappear:

\documentclass{minimal}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\input{test}
\end{document}

image

The error is in the axis section of the pgf code:

\begin{axis}[
axis background/.style={fill=white!89.80392156862746!black},
axis line style={white},
tick align=outside,
title={Simple plot $\frac{\alpha}{2}$},
x grid style={white},
xlabel={time (s)},
xmajorgrids,
xmajorticks=false,  % <--- This disables ticks and labels for x-axis
xmin=-0.095, xmax=1.995,
xtick style={color=white!33.33333333333333!black},
y grid style={white},
ylabel={Voltage (mV)},
ymajorgrids,
ymin=-1.1, ymax=1.1,
ytick pos=left,
ytick style={color=white!33.33333333333333!black}
]

Correct pgf code would use draw=none for the xtick style (see Manual for Package pgfplots, section 4.7.5):

...
xmajorticks=true,
xtick style={draw=none},
...

image

@ghost ghost changed the title Hidden ticks also remove the tick labels Hiding tick marks also removes the tick labels Aug 2, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants