Skip to content

Commit 5e9a2ef

Browse files
authored
Merge pull request #276 from nschloe/contourf
Contourf
2 parents 35a3a83 + 14e64f0 commit 5e9a2ef

13 files changed

+6631
-593
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- run: apt update
2020
# <https://stackoverflow.com/a/44333806/353337>
2121
- run: DEBIAN_FRONTEND=noninteractive apt install tzdata
22-
- run: apt install -y texlive-latex-base texlive-latex-extra python3-pip python3-tk
22+
- run: apt install -y texlive-latex-base texlive-latex-extra python3-pip python3-tk python3-scipy
2323
- run: pip3 install -U pytest pytest-cov excode
2424
- checkout
2525
- run: cd ~/work

matplotlib2tikz/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
__email__ = "[email protected]"
55
__copyright__ = u"Copyright (c) 2010-2019, {} <{}>".format(__author__, __email__)
66
__license__ = "License :: OSI Approved :: MIT License"
7-
__version__ = "0.7.0"
7+
__version__ = "0.7.1"
88
__status__ = "Development Status :: 5 - Production/Stable"

matplotlib2tikz/axes.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ def __init__(self, data, obj):
7676

7777
# aspect ratio, plot width/height
7878
aspect = obj.get_aspect()
79-
if aspect == "auto" or aspect == "normal":
79+
if aspect in ["auto", "normal"]:
8080
aspect_num = None # just take the given width/height values
8181
elif aspect == "equal":
8282
aspect_num = 1.0
8383
else:
8484
aspect_num = float(aspect)
8585

86-
self._width(data, aspect_num, xlim, ylim)
86+
self._set_axis_dimensions(data, aspect_num, xlim, ylim)
8787

8888
# axis positions
8989
xaxis_pos = obj.get_xaxis().label_position
@@ -163,7 +163,7 @@ def get_end_code(self, data):
163163

164164
return ""
165165

166-
def _width(self, data, aspect_num, xlim, ylim):
166+
def _set_axis_dimensions(self, data, aspect_num, xlim, ylim):
167167
if data["fwidth"] and data["fheight"]:
168168
# width and height overwrite aspect ratio
169169
self.axis_options.append("width=" + data["fwidth"])
@@ -193,12 +193,8 @@ def _width(self, data, aspect_num, xlim, ylim):
193193
data["fwidth"] = str(1.0 / alpha) + "*" + data["fheight"]
194194
self.axis_options.append("width=" + data["fwidth"])
195195
else:
196-
if aspect_num:
197-
print(
198-
"Non-automatic aspect ratio demanded, "
199-
"but neither height nor width of the plot are given. "
200-
"Discard aspect ratio."
201-
)
196+
# TODO keep an eye on https://tex.stackexchange.com/q/480058/13262
197+
pass
202198
return
203199

204200
def _ticks(self, data, obj):
@@ -453,17 +449,11 @@ def _get_label_rotation_and_horizontal_alignment(obj, data, axes_obj):
453449
if any(tick_labels_rotation) != 0:
454450
values.append("rotate={}".format(tick_labels_rotation[0]))
455451

452+
# Horizontal alignment will be ignored if no 'x/y tick label text width' has
453+
# been passed in the 'extra' parameter
456454
if tick_label_text_width:
457455
values.append("align={}".format(tick_labels_horizontal_alignment[0]))
458456
values.append("text width={}".format(tick_label_text_width))
459-
else:
460-
print(
461-
(
462-
"Horizontal alignment will be ignored as no '{} tick "
463-
"label text width' has been passed in the 'extra' "
464-
"parameter"
465-
).format(axes_obj)
466-
)
467457

468458
if values:
469459
label_style = "{}ticklabel style = {{{}}}".format(

matplotlib2tikz/save.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_tikz_code(
3838
extra_axis_parameters=None,
3939
extra_tikzpicture_parameters=None,
4040
dpi=None,
41-
show_info=True,
41+
show_info=False,
4242
include_disclaimer=True,
4343
standalone=False,
4444
float_format="{:.15g}",

test/refresh_reference_files.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3+
import argparse
34
import os
45
import importlib.util
56

@@ -8,15 +9,18 @@
89

910

1011
def _main():
12+
parser = argparse.ArgumentParser(description="Refresh the reference TeX files.")
13+
parser.add_argument("files", nargs="+", help="Files to refresh")
14+
args = parser.parse_args()
15+
1116
this_dir = os.path.dirname(os.path.abspath(__file__))
1217
exclude_list = ["test_rotated_labels.py", "test_deterministic_output.py"]
13-
for filename in os.listdir(this_dir):
18+
19+
for filename in args.files:
20+
if filename in exclude_list:
21+
continue
1422
if filename.startswith("test_") and filename.endswith(".py"):
1523
spec = importlib.util.spec_from_file_location("plot", filename)
16-
17-
if filename in exclude_list:
18-
continue
19-
2024
module = importlib.util.module_from_spec(spec)
2125
spec.loader.exec_module(module)
2226
module.plot()

test/test_annotate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ def plot():
3232

3333

3434
def test():
35-
assert_equality(plot, "test_annotate_reference.tex")
35+
assert_equality(plot, __file__[:-3] + "_reference.tex")
3636
return
3737

3838

3939
if __name__ == "__main__":
4040
import helpers
4141

42-
# helpers.compare_mpl_latex(plot)
43-
helpers.print_tree(plot())
42+
helpers.compare_mpl_latex(plot)
43+
# helpers.print_tree(plot())

test/test_basic_sin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ def test():
3131
if __name__ == "__main__":
3232
import helpers
3333

34-
# helpers.compare_mpl_latex(plot)
35-
helpers.print_tree(plot())
34+
helpers.compare_mpl_latex(plot)
35+
# helpers.print_tree(plot())

test/test_contourf.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,43 @@
22
#
33
import matplotlib.pyplot as plt
44
import numpy as np
5+
from scipy.stats import multivariate_normal
6+
7+
from helpers import assert_equality
58

69

710
def plot():
8-
delta = 0.8
9-
x = y = np.arange(-3.0, 3.01, delta)
10-
X, Y = np.meshgrid(x, y)
11-
Z1 = plt.mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
12-
Z2 = plt.mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
13-
Z = 10 * (Z1 - Z2)
14-
levels = [-2, -1.5, -1.2, -0.9, -0.6, -0.3, 0.0, 0.3, 0.6, 0.9, 1.2, 1.5]
11+
mean = np.array([1, 1])
12+
cov = np.eye(2)
13+
nbins = 5
14+
1515
fig = plt.figure()
16-
CS = plt.contourf(X, Y, Z, 10, levels=levels)
17-
plt.contour(CS, levels=levels, colors="r")
16+
ax = plt.gca()
17+
18+
x_max = 2
19+
x_min = 0
20+
y_max = 2
21+
y_min = 0
22+
23+
xi, yi = np.mgrid[x_min : x_max : nbins * 1j, y_min : y_max : nbins * 1j]
24+
pos = np.empty(xi.shape + (2,))
25+
pos[:, :, 0] = xi
26+
pos[:, :, 1] = yi
27+
zi = multivariate_normal(mean, cov, allow_singular=True, seed=0).pdf(pos)
28+
ax.contourf(xi, yi, zi, 250)
29+
30+
ax.set_xlim(x_min, x_max)
31+
ax.set_ylim(y_min, y_max)
1832
return fig
1933

2034

21-
# TODO reintroduce
22-
# from helpers import assert_equality
23-
# def test():
24-
# assert_equality(plot, __file__[:-3] + "_reference.tex")
25-
# return
35+
def test():
36+
assert_equality(plot, __file__[:-3] + "_reference.tex")
37+
return
38+
39+
40+
if __name__ == "__main__":
41+
import helpers
42+
43+
helpers.compare_mpl_latex(plot)
44+
# helpers.print_tree(plot())

0 commit comments

Comments
 (0)