Skip to content

Commit

Permalink
Fix dxtbx.plot_detector_models for matplotlib 3.5
Browse files Browse the repository at this point in the history
Fixes #475

Thanks @ndevenish for the report and initial starting point at matplotlib/matplotlib#21688.  That implementation didn't give us the nice Z zoom that we want, so after some digging, set_zlim gets us there.  The call to nonsingular is what set_zlim does if zmin == zmax, as is the case for a flat detector.  It seems to expand out the Z a bit. Calling it directly avoids a UserWarning.

Also fix orthographic=True (not sure when this broke)
  • Loading branch information
phyy-nx committed Feb 3, 2022
1 parent 6b8028b commit fe91d93
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions newsfragments/XXX.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix dxtbx.plot_detector_models for matplotlib 3.5
25 changes: 20 additions & 5 deletions src/dxtbx/command_line/plot_detector_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@
# http://stackoverflow.com/questions/22867620/putting-arrowheads-on-vectors-in-matplotlibs-3d-plot
class Arrow3D(FancyArrowPatch):
def __init__(self, xs, ys, zs, *args, **kwargs):
FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs)
super().__init__((0, 0), (0, 0), *args, **kwargs)
self._verts3d = xs, ys, zs

def draw(self, renderer):
def do_3d_projection(self, renderer=None):
xs3d, ys3d, zs3d = self._verts3d
xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, self.axes.M)
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
FancyArrowPatch.draw(self, renderer)

return np.min(zs)


def plot_group(
Expand Down Expand Up @@ -158,6 +159,7 @@ def run(args=None):
fig = plt.figure()
colormap = plt.cm.gist_ncar
colors = [colormap(i) for i in np.linspace(0, 0.9, len(files))]
min_z = max_z = None
for file_name, color in zip(files, colors):

# read the data and get the detector models
Expand Down Expand Up @@ -193,10 +195,23 @@ def run(args=None):
panel_numbers=params.panel_numbers,
)

if not params.orthographic:
all_z = [p.get_origin()[2] for p in detector]
if min_z is None:
min_z = min(all_z)
max_z = max(all_z)
else:
min_z = min(min_z, min(all_z))
max_z = max(max_z, max(all_z))

plt.xlabel("x")
plt.ylabel("y")
if params.orthographic:
plt.axes().set_aspect("equal", "datalim")
ax.set_aspect("equal", "datalim")
else:
if min_z == max_z:
min_z, max_z = plt.gca().zaxis.get_major_locator().nonsingular(min_z, max_z)
plt.gca().set_zlim(zmin=min_z, zmax=max_z)

if params.pdf_file:
pp = PdfPages(params.pdf_file)
Expand Down

0 comments on commit fe91d93

Please sign in to comment.