CWelling
CWelling

Reputation: 25

Set the height and width of a mpld3 plot

I want to set the width and height of a mpld3 plot to a specific value (in pixels, so it fits the div it is in). The way I tried it looks like this (javascript):

commands["width"]=plotWidth;
commands["height"]=plotHeight;
mpld3.draw_figure("plotname",commands);

plotWidth and plotHeight the values I want the height and width to be set to.

Now, this actually sets the size of the mpld3-figure object to the values I want, but the plot inside still keeps its old size, so it looks like nothing happened. So, how do I change the size of the plot itself? So far it looks like whatever I do, the plot does not change.

Upvotes: 2

Views: 5390

Answers (1)

Abraham D Flaxman
Abraham D Flaxman

Reputation: 2979

You can change the shape of an mpld3 plot when creating a figure with the python code plt.figure(figsize=(width,height)) (where width and height are in inches). Here is a notebook demonstrating this.

There has been some interest in making mpld3 figures "responsive", which would be a cooler and more precise way to accomplish your goal, but so far no one has tried making the necessary code changes. Patches welcome!

Upvotes: 7

Related Questions