Skip to content

Commit

Permalink
[vis] Fix limits of quiver plots
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Holl committed Oct 7, 2024
1 parent 8e08cd6 commit a72de92
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion phi/vis/_matplotlib/_matplotlib_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def plot(self, data: Field, figure, subplot, space: Box, min_val: float, max_val
class StreamPlot2D(Recipe):

def can_plot(self, data: Field, space: Box) -> bool:
return data.spatial_rank == 2 and 'vector' in channel(data) and data.is_grid and (data.values != 0).any
return data.spatial_rank == 2 and 'vector' in channel(data) and data.is_grid and (data.values != 0).any and all(dim.size > 1 for dim in data.resolution)

def plot(self, data: Field, figure, subplot, space: Box, min_val: float, max_val: float, show_color_bar: bool, color: Tensor, alpha: Tensor, err: Tensor):
vector = data.geometry.shape['vector']
Expand Down
6 changes: 5 additions & 1 deletion phi/vis/_vis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from threading import Lock
from typing import Tuple, Any, Optional, Dict, Callable, Union, Sequence

from phi import field, math
from phi import field, math, geom
from phi.field import Field, Scene, PointCloud, CenteredGrid
from phi.field._field_math import data_bounds
from phi.geom import Box, Cuboid, Geometry, Point
Expand Down Expand Up @@ -548,6 +548,10 @@ def get_default_limits(f: Field, all_dims: Optional[Sequence[str]], log_dims: Tu
is_log = wrap([dim in log_dims for dim in f_dims], channel(vector=f_dims))
if math.equal(0, err):
bounding_box = f.geometry.bounding_box()
if 'vector' in f.values.shape:
target_points = f.points + f.values
target_bounds = geom.bounding_box(target_points)
bounding_box = geom.union(bounding_box, target_bounds).largest('union')
if value_axis:
bounding_box *= Box(_=(math.finite_min(f.values), math.finite_max(f.values)))
return _limits(bounding_box.center, bounding_box.half_size, is_log)
Expand Down

0 comments on commit a72de92

Please sign in to comment.