Skip to content

Commit

Permalink
PEP-8 Compliance, support for latest
Browse files Browse the repository at this point in the history
matplotlib version (3.8)
  • Loading branch information
isaacrobinson2000 committed Dec 15, 2023
1 parent e23934c commit 6e3bca8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions matplotview/_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def dynamic_doc_string(**kwargs):
def convert(func):
default_vals = {
k: v.default for k, v in inspect.signature(func).parameters.items()
if(v.default is not inspect.Parameter.empty)
if (v.default is not inspect.Parameter.empty)
}
default_vals.update(kwargs)
func.__doc__ = func.__doc__.format(**default_vals)
Expand All @@ -18,6 +18,6 @@ def convert(func):
def get_interpolation_list_str():
from matplotlib.image import _interpd_
return ", ".join([
f"'{k}'" if(i != len(_interpd_) - 1) else f"or '{k}'"
f"'{k}'" if (i != len(_interpd_) - 1) else f"or '{k}'"
for i, k in enumerate(_interpd_)
])
28 changes: 14 additions & 14 deletions matplotview/_transform_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _scale_gc(self, gc: GraphicsContextBase) -> GraphicsContextBase:
unit_box = transfer_transform.transform_bbox(unit_box)
mult_factor = np.sqrt(unit_box.width * unit_box.height)

if(mult_factor == 0 or (not np.isfinite(mult_factor))):
if (mult_factor == 0 or (not np.isfinite(mult_factor))):
return new_gc

new_gc.set_linewidth(gc.get_linewidth() * mult_factor)
Expand Down Expand Up @@ -218,18 +218,18 @@ def draw_path(

# We check if the path intersects the axes box at all, if not don't
# waste time drawing it.
if(not path.intersects_bbox(bbox, True)):
if (not path.intersects_bbox(bbox, True)):
return

if(self.__scale_widths):
if (self.__scale_widths):
gc = self._scale_gc(gc)

# Change the clip to the sub-axes box
gc.set_clip_rectangle(bbox)
if(not isinstance(self.__bounding_axes.patch, Rectangle)):
if (not isinstance(self.__bounding_axes.patch, Rectangle)):
gc.set_clip_path(TransformedPatchPath(self.__bounding_axes.patch))

rgbFace = tuple(rgbFace) if(rgbFace is not None) else None
rgbFace = tuple(rgbFace) if (rgbFace is not None) else None

self.__renderer.draw_path(gc, path, IdentityTransform(), rgbFace)

Expand All @@ -244,7 +244,7 @@ def _draw_text_as_path(
ismath: bool
):
# If the text field is empty, don't even try rendering it...
if((s is None) or (s.strip() == "")):
if ((s is None) or (s.strip() == "")):
return

# Call the super class instance, which works for all cases except one
Expand All @@ -264,14 +264,14 @@ def draw_gouraud_triangle(
path = Path(points, closed=True)
bbox = self._get_axes_display_box()

if(not path.intersects_bbox(bbox, True)):
if (not path.intersects_bbox(bbox, True)):
return

if(self.__scale_widths):
if (self.__scale_widths):
gc = self._scale_gc(gc)

gc.set_clip_rectangle(bbox)
if(not isinstance(self.__bounding_axes.patch, Rectangle)):
if (not isinstance(self.__bounding_axes.patch, Rectangle)):
gc.set_clip_path(TransformedPatchPath(self.__bounding_axes.patch))

self.__renderer.draw_gouraud_triangle(gc, path.vertices, colors,
Expand Down Expand Up @@ -299,15 +299,15 @@ def draw_image(
out_box = img_bbox_disp.transformed(shift_data_transform)
clipped_out_box = Bbox.intersection(out_box, axes_bbox)

if(clipped_out_box is None):
if (clipped_out_box is None):
return

# We compute what the dimensions of the final output image within the
# sub-axes are going to be.
x, y, out_w, out_h = clipped_out_box.bounds
out_w, out_h = int(np.ceil(out_w * mag)), int(np.ceil(out_h * mag))

if((out_w <= 0) or (out_h <= 0)):
if ((out_w <= 0) or (out_h <= 0)):
return

# We can now construct the transform which converts between the
Expand All @@ -330,16 +330,16 @@ def draw_image(
alpha=1)
out_arr[:, :, 3] = trans_msk

if(self.__scale_widths):
if (self.__scale_widths):
gc = self._scale_gc(gc)

gc.set_clip_rectangle(clipped_out_box)
if(not isinstance(self.__bounding_axes.patch, Rectangle)):
if (not isinstance(self.__bounding_axes.patch, Rectangle)):
gc.set_clip_path(TransformedPatchPath(self.__bounding_axes.patch))

x, y = clipped_out_box.x0, clipped_out_box.y0

if(self.option_scale_image()):
if (self.option_scale_image()):
self.__renderer.draw_image(gc, x, y, out_arr, None)
else:
self.__renderer.draw_image(gc, x, y, out_arr)
29 changes: 14 additions & 15 deletions matplotview/_view_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def draw(self, renderer: RendererBase):

# If we are working with a 3D object, swap out it's axes with
# this zoom axes (swapping out the 3d transform) and reproject it.
if(hasattr(self._artist, "do_3d_projection")):
if (hasattr(self._artist, "do_3d_projection")):
self.do_3d_projection()

# Check and see if the passed limiting box and extents of the
# artist intersect, if not don't bother drawing this artist.
# First 2 checks are a special case where we received a bad clip box.
# (those can happen when we try to get the bounds of a map projection)
if(
if (
self._clip_box.width == 0 or self._clip_box.height == 0 or
Bbox.intersection(full_extents, self._clip_box) is not None
):
Expand Down Expand Up @@ -128,7 +128,7 @@ class ViewSpecification:

def __post_init__(self):
self.image_interpolation = str(self.image_interpolation)
if(self.filter_set is not None):
if (self.filter_set is not None):
self.filter_set = set(self.filter_set)
self.scale_lines = bool(self.scale_lines)

Expand All @@ -138,7 +138,6 @@ class __ViewType:
PRIVATE: A simple identifier class for identifying view types, a view
will inherit from the axes class it is wrapping and this type...
"""
...


# Cache classes so grabbing the same type twice leads to actually getting the
Expand All @@ -162,7 +161,7 @@ def view_wrapper(axes_class: Type[Axes]) -> Type[Axes]:
another axes contents...
"""
# If the passed class is a view, simply return it.
if(issubclass(axes_class, Axes) and issubclass(axes_class, __ViewType)):
if (issubclass(axes_class, Axes) and issubclass(axes_class, __ViewType)):
return axes_class

class View(axes_class, __ViewType):
Expand Down Expand Up @@ -228,14 +227,14 @@ def get_children(self) -> List[Artist]:
child_list = super().get_children()

def filter_check(artist, filter_set):
if(filter_set is None):
if (filter_set is None):
return True
return (
(artist not in filter_set)
and (type(artist) not in filter_set)
)

if(self.__renderer is not None):
if (self.__renderer is not None):
for ax, spec in self.view_specifications.items():
mock_renderer = _TransformRenderer(
self.__renderer, ax.transData, self.transData,
Expand All @@ -253,7 +252,7 @@ def filter_check(artist, filter_set):
for a in itertools.chain(
ax._children,
ax.child_axes
) if(filter_check(a, spec.filter_set))
) if (filter_check(a, spec.filter_set))
])

return child_list
Expand All @@ -262,7 +261,7 @@ def draw(self, renderer: RendererBase = None):
# It is possible to have two axes which are views of each other
# therefore we track the number of recursions and stop drawing
# at a certain depth
if(self.figure._current_render_depth >= self.__max_render_depth):
if (self.figure._current_render_depth >= self.__max_render_depth):
return
self.figure._current_render_depth += 1
# Set the renderer, causing get_children to return the view's
Expand All @@ -281,7 +280,7 @@ def __reduce__(self):
cls = type(self)

args = tuple(
arg if(arg != cls) else cls.__bases__[0] for arg in args
arg if (arg != cls) else cls.__bases__[0] for arg in args
)

return (
Expand Down Expand Up @@ -318,7 +317,7 @@ def set_max_render_depth(self, val: int):
allow. Zero and negative values are invalid, and will raise a
ValueError.
"""
if(val <= 0):
if (val <= 0):
raise ValueError(f"Render depth must be positive, not {val}.")
self.__max_render_depth = val

Expand Down Expand Up @@ -376,20 +375,20 @@ def from_axes(
If the provided axes to convert has an Axes type which does
not match the axes class this view type wraps.
"""
if(isinstance(axes, cls)):
if(render_depth is not None):
if (isinstance(axes, cls)):
if (render_depth is not None):
axes.set_max_render_depth(render_depth)
return axes

if(type(axes) != axes_class):
if (type(axes) is not axes_class):
raise TypeError(
f"Can't convert {type(axes).__name__} to {cls.__name__}"
)

axes.__class__ = cls
axes._init_vars(
DEFAULT_RENDER_DEPTH
if(render_depth is None)
if (render_depth is None)
else render_depth
)
return axes
Expand Down
5 changes: 3 additions & 2 deletions matplotview/tests/test_view_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ def test_obj_comparison():

assert view_class1 is view_class2
assert view_class1 == view_class2
if(mpl_version >= (3, 7)):
# As of 3.7.0, the subplot class no longer exists, and is an alias to the Axes class...
if (mpl_version >= (3, 7)):
# As of 3.7.0, the subplot class no longer exists, and is an alias
# to the Axes class...
assert view_class2 == view_class3
else:
assert view_class2 != view_class3
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import setuptools

VERSION = "1.0.0"
VERSION = "1.0.1"

with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
Expand Down

0 comments on commit 6e3bca8

Please sign in to comment.