Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/fix-powder-hkl-plot.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Fixed powder pattern plot(hkl=True) when used before the figure has been displayed at least once.

**Security:**

* <news item>
14 changes: 13 additions & 1 deletion src/pyobjcryst/powderpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ def __init__(self):
self._plot_hkl = False
self._plot_hkl_fontsize = 6
self._plot_phase_labels = None

# xlim last time hkl were plotted
self._last_hkl_plot_xlim = None

# Used to avoid issues with get_window_extent
# before figure is actually rendered
self._plot_fig_displayed_once = False

self.evts = []
self._colour_phases = [
"black",
Expand Down Expand Up @@ -155,6 +161,7 @@ def plot(
x = np.rad2deg(self.GetPowderPatternX())
if self._plot_fig is None or "inline" in plt.get_backend():
self._plot_fig = plt.figure(figsize=figsize)
self._plot_fig_displayed_once = False
else:
self._plot_fig.clear()
ax = (
Expand Down Expand Up @@ -234,6 +241,8 @@ def plot(
self._plot_fig.canvas.mpl_connect(
"draw_event", self._on_draw_event
)
# TODO: There may be cases where this is not true
self._plot_fig_displayed_once = True

def _do_plot_hkl(self, nb_max=100, fontsize_hkl=None):
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -313,7 +322,10 @@ def _do_plot_hkl(self, nb_max=100, fontsize_hkl=None):
fontweight="light",
color=self._colour_phases[iphase],
)
if renderer is not None:
# get_window_extent gets stuck if image has not yet
# been completely rendered, preventing the display
# of the figure (%matplotlib widget)
if renderer is not None and self._plot_fig_displayed_once:
# Check for overlap with previous
bbox = t.get_window_extent(renderer)
# print(s, bbox)
Expand Down
Loading