Skip to content

Commit 84a22fb

Browse files
authored
Merge pull request #341 from nschloe/fix-339
protect against int/float in xdata
2 parents 4406b3b + 1364c5f commit 84a22fb

File tree

6 files changed

+64
-21
lines changed

6 files changed

+64
-21
lines changed

.circleci/config.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,34 @@ version: 2
33
jobs:
44
lint:
55
docker:
6-
- image: ubuntu:18.04
6+
- image: circleci/python:3.7
77
steps:
88
- checkout
9-
- run: apt update
10-
- run: apt install -y python3-pip
11-
- run: pip3 install -U black flake8
12-
- run: LC_ALL=C.UTF-8 black --check .
9+
- run: pip3 install -U black flake8 --user
10+
- run: black --check .
1311
- run: flake8 .
1412
build:
1513
working_directory: ~/work
1614
docker:
17-
- image: ubuntu:18.04
15+
- image: circleci/python:3.7
1816
steps:
19-
- run: apt update
17+
- run: sudo apt update
2018
# <https://stackoverflow.com/a/44333806/353337>
21-
- run: DEBIAN_FRONTEND=noninteractive apt install tzdata
22-
- run: apt install -y texlive-latex-base texlive-latex-extra python3-pip python3-tk python3-scipy
23-
- run: pip3 install -U pytest pytest-cov excode
19+
- run: DEBIAN_FRONTEND=noninteractive sudo apt install tzdata
20+
- run: sudo apt install -y texlive-latex-base texlive-latex-extra
21+
- run: pip3 install -U pytest pytest-cov excode --user
2422
- checkout
25-
- run: cd ~/work
2623
- run: excode README.md test/zzz_readme_test.py --filter python,test
27-
- run: pip3 install -r test_requirements.txt
28-
- run: pip3 install .[all]
24+
- run: pip3 install -r test_requirements.txt --user
25+
- run: pip3 install .[all] --user
2926
- run: pip3 check
3027
# The actual test
31-
- run: cd test/ && MPLBACKEND=Agg pytest --cov tikzplotlib
28+
- run:
29+
command: pytest --cov tikzplotlib
30+
working_directory: test/
31+
environment:
32+
MPLBACKEND: Agg
3233
# submit to codecov
33-
- run: apt install -y curl
3434
- run: bash <(curl -s https://codecov.io/bash)
3535

3636
workflows:

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ jobs:
4242
pip install pytest pytest-cov
4343
pip install -r test_requirements.txt
4444
cd test/ && MPLBACKEND=Agg pytest --cov tikzplotlib
45-
- name: Submit to codecov
46-
run: bash <(curl -s https://codecov.io/bash) -R ~/work/tikzplotlib
45+
# - name: Submit to codecov
46+
# run: bash <(curl -s https://codecov.io/bash)

test/refresh_reference_files.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import matplotlib.pyplot as plt
66

7-
import tikzplotlib as m2t
7+
import tikzplotlib as tpl
88

99

1010
def _main():
@@ -24,7 +24,7 @@ def _main():
2424
spec.loader.exec_module(module)
2525
module.plot()
2626

27-
code = m2t.get_tikz_code(include_disclaimer=False)
27+
code = tpl.get_tikz_code(include_disclaimer=False)
2828
plt.close()
2929

3030
tex_filename = filename[:-3] + "_reference.tex"

test/test_line_set_data.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# from <https://github.com/nschloe/tikzplotlib/issues/339>
2+
import matplotlib.pyplot as plt
3+
4+
from helpers import assert_equality
5+
6+
7+
def plot():
8+
fig = plt.figure()
9+
line = plt.plot(0, 0, "kx")[0]
10+
line.set_data(0, 0)
11+
return fig
12+
13+
14+
def test():
15+
assert_equality(plot, "test_line_set_data_reference.tex")
16+
return

test/test_line_set_data_reference.tex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
\begin{tikzpicture}
2+
3+
\begin{axis}[
4+
tick align=outside,
5+
tick pos=left,
6+
x grid style={white!69.01960784313725!black},
7+
xmin=-0.055, xmax=0.055,
8+
xtick style={color=black},
9+
y grid style={white!69.01960784313725!black},
10+
ymin=-0.055, ymax=0.055,
11+
ytick style={color=black}
12+
]
13+
\addplot [semithick, black, mark=x, mark size=3, mark options={solid}, only marks]
14+
table {%
15+
0 0
16+
};
17+
\end{axis}
18+
19+
\end{tikzpicture}

tikzplotlib/line2d.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ def draw_line2d(data, obj):
1818
# If line is of length 0, do nothing. Otherwise, an empty \addplot table will be
1919
# created, which will be interpreted as an external data source in either the file
2020
# '' or '.tex'. Instead, render nothing.
21-
if len(obj.get_xdata()) == 0:
21+
xdata = obj.get_xdata()
22+
if isinstance(xdata, int) or isinstance(xdata, float):
23+
# https://github.com/nschloe/tikzplotlib/issues/339
24+
xdata = [xdata]
25+
26+
if len(xdata) == 0:
2227
return data, []
2328

2429
# get the linewidth (in pt)
@@ -250,12 +255,15 @@ def _marker(
250255
return
251256

252257

253-
def _table(obj, data):
258+
def _table(obj, data): # noqa: C901
254259
# get_xydata() always gives float data, no matter what
255260
xdata, ydata = obj.get_xydata().T
256261

257262
# get_{x,y}data gives datetime or string objects if so specified in the plotter
258263
xdata_alt = obj.get_xdata()
264+
if isinstance(xdata_alt, int) or isinstance(xdata, float):
265+
# https://github.com/nschloe/tikzplotlib/issues/339
266+
xdata_alt = [xdata_alt]
259267

260268
ff = data["float format"]
261269

0 commit comments

Comments
 (0)