Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix matplotlib 3.10 compatibility with visualizers #271

Merged
merged 2 commits into from
Jan 2, 2025
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
6 changes: 3 additions & 3 deletions pyRDDLGym/core/visualizer/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ def _setup(self):

def convert2img(self, fig, ax):
fig.canvas.draw()
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
data = np.frombuffer(fig.canvas.buffer_rgba(), dtype=np.uint8)
data = data.reshape(fig.canvas.get_width_height()[::-1] + (4,))
data = data[:, :, :3]
img = Image.fromarray(data)
self._data = data
self._img = img
return img

Expand Down
6 changes: 3 additions & 3 deletions pyRDDLGym/core/visualizer/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ def _setup(self):

def convert2img(self, fig, ax):
fig.canvas.draw()
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
data = np.frombuffer(fig.canvas.buffer_rgba(), dtype=np.uint8)
data = data.reshape(fig.canvas.get_width_height()[::-1] + (4,))
data = data[:, :, :3]
img = Image.fromarray(data)
self._data = data
self._img = img
return img

Expand Down
6 changes: 3 additions & 3 deletions pyRDDLGym/core/visualizer/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def init_canvas(self, figure_size, dpi):
def convert2img(self, fig, ax):
ax.set_position((0, 0, 1, 1))
fig.canvas.draw()
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
data = np.frombuffer(fig.canvas.buffer_rgba(), dtype=np.uint8)
data = data.reshape(fig.canvas.get_width_height()[::-1] + (4,))
data = data[:, :, :3]
img = Image.fromarray(data)
self._data = data
self._img = img
return img

Expand Down