Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Remove matplotlib stretch effect in `mo.ui.matplotlib` (#8883)

vincent d warmerdam2c42af823fef
diff --git a/frontend/src/plugins/impl/matplotlib/matplotlib-renderer.ts b/frontend/src/plugins/impl/matplotlib/matplotlib-renderer.ts
index cdedd67a1f..789d48f616 100644
--- a/frontend/src/plugins/impl/matplotlib/matplotlib-renderer.ts
+++ b/frontend/src/plugins/impl/matplotlib/matplotlib-renderer.ts
@@ -301,8 +301,9 @@ export class MatplotlibRenderer {
canvas.width = this.#state.width * dpr;
canvas.height = this.#state.height * dpr;
canvas.style.width = `${this.#state.width}px`;
- canvas.style.height = `${this.#state.height}px`;
canvas.style.maxWidth = "100%";
+ canvas.style.height = "auto";
+ canvas.style.aspectRatio = `${this.#state.width} / ${this.#state.height}`;
canvas.style.touchAction = "none";
container.append(canvas);
this.#canvas = canvas;
@@ -344,7 +345,9 @@ export class MatplotlibRenderer {
this.#canvas.width = state.width * dpr;
this.#canvas.height = state.height * dpr;
this.#canvas.style.width = `${state.width}px`;
- this.#canvas.style.height = `${state.height}px`;
+ this.#canvas.style.maxWidth = "100%";
+ this.#canvas.style.height = "auto";
+ this.#canvas.style.aspectRatio = `${state.width} / ${state.height}`;
needsRedraw = true;
}