Skip to content

Commit

Permalink
Merge pull request #399 from nschloe/fix-warning
Browse files Browse the repository at this point in the history
Fix warning
  • Loading branch information
nschloe committed Apr 6, 2020
2 parents 4acb140 + c5a2476 commit d88bb1e
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 70 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<a href="https://github.com/nschloe/tikzplotlib"><img alt="tikzplotlib" src="https://nschloe.github.io/tikzplotlib/logo-tikzplotlib.svg" width="60%"></a>
<p align="center">The artist formerly known as _matplotlib2tikz._</p>
<p align="center">The artist formerly known as *matplotlib2tikz.*</p>
</p>

[![CircleCI](https://img.shields.io/circleci/project/github/nschloe/tikzplotlib/master.svg?style=flat-square)](https://circleci.com/gh/nschloe/tikzplotlib/tree/master)
Expand Down
48 changes: 28 additions & 20 deletions test/refresh_reference_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,36 @@


def _main():
parser = argparse.ArgumentParser(description="Refresh the reference TeX files.")
parser.add_argument("files", nargs="+", help="Files to refresh")
args = parser.parse_args()
parser = argparse.ArgumentParser(description="Refresh all reference TeX files.")
parser.parse_args()

this_dir = os.path.dirname(os.path.abspath(__file__))
exclude_list = ["test_rotated_labels.py", "test_deterministic_output.py"]

for filename in args.files:
if filename in exclude_list:
continue
if filename.startswith("test_") and filename.endswith(".py"):
spec = importlib.util.spec_from_file_location("plot", filename)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
module.plot()

code = tpl.get_tikz_code(include_disclaimer=False, float_format=".8g")
plt.close()

tex_filename = filename[:-3] + "_reference.tex"
with open(os.path.join(this_dir, tex_filename), "w", encoding="utf8") as f:
f.write(code)

test_files = [
f
for f in os.listdir(this_dir)
if os.path.isfile(os.path.join(this_dir, f))
and f[:5] == "test_"
and f[-3:] == ".py"
]
test_modules = [f[:-3] for f in test_files]

# remove some edge cases
test_modules.remove("test_rotated_labels")
test_modules.remove("test_deterministic_output")
test_modules.remove("test_cleanfigure")
test_modules.remove("test_context")

for mod in test_modules:
module = importlib.import_module(mod)
module.plot()

code = tpl.get_tikz_code(include_disclaimer=False, float_format=".8g")
plt.close()

tex_filename = mod + "_reference.tex"
with open(os.path.join(this_dir, tex_filename), "w", encoding="utf8") as f:
f.write(code)


if __name__ == "__main__":
Expand Down
72 changes: 35 additions & 37 deletions test/test_colorbars_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -37,65 +37,63 @@
tick pos=left,
x grid style={white!69.019608!black},
xlabel={Discrete intervals, some other units},
xmin=-0.05, xmax=1.05,
xmin=0.65, xmax=8.35,
xtick style={color=black},
xtick={0,0.14285714,0.42857143,0.85714286,1},
xtick={1,2,4,7,8},
xticklabels={1,2,4,7,8},
ymin=0, ymax=1
ymin=1, ymax=8
]
\path [draw=white, fill=white, line width=0.004pt]
(axis cs:-0.05,0.5)
--(axis cs:0,0)
--(axis cs:1,0)
--(axis cs:1.05,0.5)
--(axis cs:1.05,0.5)
(axis cs:0.65,4.5)
--(axis cs:1,1)
--(axis cs:0,1)
--(axis cs:-0.05,0.5)
--(axis cs:8,1)
--(axis cs:8.35,4.5)
--(axis cs:8.35,4.5)
--(axis cs:8,8)
--(axis cs:1,8)
--(axis cs:0.65,4.5)
--cycle;
\addplot graphics [includegraphics cmd=\pgfimage,xmin=-0.05, xmax=1.05, ymin=0, ymax=1] {tmp-001.png};
\addplot graphics [includegraphics cmd=\pgfimage,xmin=0.65, xmax=8.35, ymin=1, ymax=8] {tmp-001.png};
\path [draw=black, line width=0.32pt]
(axis cs:-0.05,0.5)
--(axis cs:0,0)
--(axis cs:1,0)
--(axis cs:1.05,0.5)
--(axis cs:1.05,0.5)
(axis cs:0.65,4.5)
--(axis cs:1,1)
--(axis cs:0,1)
--(axis cs:-0.05,0.5)
--(axis cs:8,1)
--(axis cs:8.35,4.5)
--(axis cs:8.35,4.5)
--(axis cs:8,8)
--(axis cs:1,8)
--(axis cs:0.65,4.5)
--cycle;

\nextgroupplot[
tick align=outside,
tick pos=left,
x grid style={white!69.019608!black},
xlabel={Custom extension lengths, some other units},
xmin=-0.25, xmax=1.25,
xmin=-1.5, xmax=1.5,
xtick style={color=black},
xtick={0,0.25,0.5,0.75,1},
xticklabels={−1.0,−0.5,0.0,0.5,1.0},
ymin=0, ymax=1
ymin=-1, ymax=1
]
\path [draw=white, fill=white, line width=0.004pt]
(axis cs:-0.25,0.5)
--(axis cs:0,0)
--(axis cs:1,0)
--(axis cs:1.25,0.5)
--(axis cs:1.25,0.5)
(axis cs:-1.5,0)
--(axis cs:-1,-1)
--(axis cs:1,-1)
--(axis cs:1.5,0)
--(axis cs:1.5,0)
--(axis cs:1,1)
--(axis cs:0,1)
--(axis cs:-0.25,0.5)
--(axis cs:-1,1)
--(axis cs:-1.5,0)
--cycle;
\addplot graphics [includegraphics cmd=\pgfimage,xmin=-0.25, xmax=1.25, ymin=0, ymax=1] {tmp-002.png};
\addplot graphics [includegraphics cmd=\pgfimage,xmin=-1.5, xmax=1.5, ymin=-1, ymax=1] {tmp-002.png};
\path [draw=black, line width=0.32pt]
(axis cs:-0.25,0.5)
--(axis cs:0,0)
--(axis cs:1,0)
--(axis cs:1.25,0.5)
--(axis cs:1.25,0.5)
(axis cs:-1.5,0)
--(axis cs:-1,-1)
--(axis cs:1,-1)
--(axis cs:1.5,0)
--(axis cs:1.5,0)
--(axis cs:1,1)
--(axis cs:0,1)
--(axis cs:-0.25,0.5)
--(axis cs:-1,1)
--(axis cs:-1.5,0)
--cycle;
\end{groupplot}

Expand Down
4 changes: 2 additions & 2 deletions test/test_legend_line_scatter_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
tick align=outside,
tick pos=left,
x grid style={white!69.019608!black},
xmin=-0.22927419, xmax=4.2292742,
xmin=-0.2, xmax=4.2,
xtick style={color=black},
y grid style={white!69.019608!black},
ymin=-0.23928571, ymax=4.2392857,
ymin=-0.2, ymax=4.2,
ytick style={color=black}
]
\addplot [only marks, mark=*, draw=color0, fill=color0, colormap/viridis]
Expand Down
4 changes: 2 additions & 2 deletions test/test_scatter_colormap_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
tick align=outside,
tick pos=left,
x grid style={white!69.019608!black},
xmin=-2.6372526, xmax=1.8614963,
xmin=-2.630585, xmax=1.8553423,
xtick style={color=black},
y grid style={white!69.019608!black},
ymin=-0.83585322, ymax=2.3593314,
ymin=-0.82312696, ymax=2.3501709,
ytick style={color=black}
]
\addplot [only marks, scatter, scatter src=explicit, colormap/viridis, visualization depends on={\thisrow{sizedata} \as\perpointmarksize}, scatter/@pre marker code/.append style={/tikz/mark size=\perpointmarksize}]
Expand Down
4 changes: 2 additions & 2 deletions test/test_scatter_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
tick pos=left,
x grid style={white!79.607843!black},
xmajorgrids,
xmin=-5.0066532, xmax=105.00665,
xmin=-5, xmax=105,
xtick style={color=black},
y grid style={white!79.607843!black},
ymajorgrids,
ymin=0.16291984, ymax=112.82609,
ymin=0.17184841, ymax=112.81716,
ytick style={color=black}
]
\addplot [only marks, mark=*, draw=color0, fill=color0, colormap/viridis]
Expand Down
18 changes: 12 additions & 6 deletions tikzplotlib/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,18 @@ def _ticks(self, data, obj):
)
self.axis_options.extend(
_get_ticks(
data, "minor x", obj.get_xticks("minor"), obj.get_xticklabels("minor")
data,
"minor x",
obj.get_xticks(minor=True),
obj.get_xticklabels(minor=True),
)
)
self.axis_options.extend(
_get_ticks(
data, "minor y", obj.get_yticks("minor"), obj.get_yticklabels("minor")
data,
"minor y",
obj.get_yticks(minor=True),
obj.get_yticklabels(minor=True),
)
)

Expand Down Expand Up @@ -323,7 +329,7 @@ def _colorbar(self, colorbar, data):
self.axis_options.append("colorbar horizontal")

colorbar_ticks = colorbar.ax.get_xticks()
colorbar_ticks_minor = colorbar.ax.get_xticks("minor")
colorbar_ticks_minor = colorbar.ax.get_xticks(minor=True)
axis_limits = colorbar.ax.get_xlim()

# In matplotlib, the colorbar color limits are determined by get_clim(), and
Expand All @@ -339,7 +345,7 @@ def _colorbar(self, colorbar, data):
# Getting the labels via get_* might not actually be suitable:
# they might not reflect the current state.
colorbar_ticklabels = colorbar.ax.get_xticklabels()
colorbar_ticklabels_minor = colorbar.ax.get_xticklabels("minor")
colorbar_ticklabels_minor = colorbar.ax.get_xticklabels(minor=True)

colorbar_styles.extend(
_get_ticks(data, "x", colorbar_ticks, colorbar_ticklabels)
Expand All @@ -355,7 +361,7 @@ def _colorbar(self, colorbar, data):

self.axis_options.append("colorbar")
colorbar_ticks = colorbar.ax.get_yticks()
colorbar_ticks_minor = colorbar.ax.get_yticks("minor")
colorbar_ticks_minor = colorbar.ax.get_yticks(minor=True)
axis_limits = colorbar.ax.get_ylim()

# In matplotlib, the colorbar color limits are determined by get_clim(), and
Expand All @@ -373,7 +379,7 @@ def _colorbar(self, colorbar, data):
# they might not reflect the current state.
colorbar_ticklabels = colorbar.ax.get_yticklabels()
colorbar_ylabel = colorbar.ax.get_ylabel()
colorbar_ticklabels_minor = colorbar.ax.get_yticklabels("minor")
colorbar_ticklabels_minor = colorbar.ax.get_yticklabels(minor=True)
colorbar_styles.extend(
_get_ticks(data, "y", colorbar_ticks, colorbar_ticklabels)
)
Expand Down

0 comments on commit d88bb1e

Please sign in to comment.