Skip to content

Commit

Permalink
BUG: fix two bugs in yt.visualization.eps_writer where
Browse files Browse the repository at this point in the history
- a call to get_cmap was syntaxically erroneous
- filename argument didn't accept Path objects
  • Loading branch information
neutrinoceros committed Sep 1, 2021
1 parent bff9354 commit 5511de2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nose_unit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ nologcapture=1
verbosity=2
where=yt
with-timer=1
ignore-files=(test_load_errors.py|test_load_sample.py|test_commons.py|test_ambiguous_fields.py|test_field_access_pytest.py|test_save.py|test_line_annotation_unit.py)
ignore-files=(test_load_errors.py|test_load_sample.py|test_commons.py|test_ambiguous_fields.py|test_field_access_pytest.py|test_save.py|test_line_annotation_unit.py|test_eps_writer.py)
exclude-test=yt.frontends.gdf.tests.test_outputs.TestGDF
1 change: 1 addition & 0 deletions tests/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ other_tests:
- '--ignore-files=test_load_sample.py'
- '--ignore-files=test_field_access_pytest.py'
- '--ignore-files=test_ambiguous_fields.py'
- '--ignore-files=test_eps_writer.py'
- "--ignore-files=test_save.py"
- '--exclude-test=yt.frontends.gdf.tests.test_outputs.TestGDF'
cookbook:
Expand Down
5 changes: 4 additions & 1 deletion yt/visualization/eps_writer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import numpy as np
import pyx
from matplotlib import cm, pyplot as plt
Expand Down Expand Up @@ -743,7 +745,7 @@ def colorbar(

# Convert the colormap into a string
x = np.linspace(1, 0, 256)
cm_string = cm.get_cmap[name](x, bytes=True)[:, 0:3].tobytes()
cm_string = cm.get_cmap(name)(x, bytes=True)[:, 0:3].tobytes()

cmap_im = pyx.bitmap.image(imsize[0], imsize[1], "RGB", cm_string)
if orientation == "top" or orientation == "bottom":
Expand Down Expand Up @@ -1143,6 +1145,7 @@ def save_fig(self, filename="test", format="eps", resolution=250):
>>> d = DualEPS()
>>> d.axis_box(xrange=(0, 100), yrange=(1e-3, 1), ylog=True)
"""
filename = os.path.expanduser(filename)
if format == "eps":
self.canvas.writeEPSfile(filename)
elif format == "pdf":
Expand Down
27 changes: 27 additions & 0 deletions yt/visualization/tests/test_eps_writer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import yt
from yt.testing import fake_amr_ds, requires_module_pytest


@requires_module_pytest("pyx")
def test_eps_writer(tmp_path):
import yt.visualization.eps_writer as eps

fields = [
("gas", "density"),
("gas", "temperature"),
]
units = [
"g/cm**3",
"K",
]
ds = fake_amr_ds(fields=fields, units=units)
slc = yt.SlicePlot(
ds,
"z",
fields=fields,
)
eps_fig = eps.multiplot_yt(2, 1, slc, bare_axes=True)
eps_fig.scale_line(0.2, "5 cm")
savefile = tmp_path / "multi"
eps_fig.save_fig(savefile, format="eps")
assert savefile.with_suffix(".eps").exists

0 comments on commit 5511de2

Please sign in to comment.