How to change size of VS Code jupyter notebook graphs?

Question:

My problem is that when I use google collab to display graphs they are much bigger, but recently I have switched from google collab to vs code jupyter notebook but when I try to display a graph is much smaller. Is there a way to change the graph size on vs code jupyter notebook. BTW I am using plotly.

Asked By: Zues

||

Answers:

You may try it in VS Code Insider, which shows the bigger graph.

VS Code Insider:
enter image description here

VS Code:
enter image description here

[UPDATE]

Plotly would decide if the graph takes up the full width or not. And i’m sorry to tell you there’s no way to change the graph size now and the insiders making it larger is actually a bug. Detailed information please view How to change graph size.

Answered By: Molly Wang-MSFT

I know in matplotlib you can do something like this:

import matplotlib as mpl
mpl.rcParams['figure.dpi'] = 150

This will change the graph size for all cells that follow. You can set to a different size in a later cell if you want to.

Answered By: Todd Miller

You can use props width=[int], height=[int] after x, y params of the graph. If omit width the graph will fill whole cells width. Tested on VSC 1.63.2

Answered By: Dimitar Petkov

Similar to Todd Millers answer you can also change the fig size:

import matplotlib as mpl
mpl.rcParams['figure.figsize'] = [10, 10]

which helped me a lot.
Further options here.

Answered By: downbydawn

As OP is using Plotly, let’s say that one has a plotly.express.scatter_matrix as follows

fig = px.scatter_matrix(M25C_df, dimensions=['PRECO_ES', '1_Mean', '2_Mean', '3_Mean', 'Eolica_Mean', 'Nuclear_Mean', 'Carvao_Mean', 'CCombinado_Mean', 'Hidro_Mean', 'IntInter_Mean', 'Solar_Mean'], color='PRECO_ES')

fig.show()

enter image description here

If one wants to increase it’s size, one can use .update_layout as follows (then adjust to the desired width and height)

fig = px.scatter_matrix(M25C_df, dimensions=['PRECO_ES', '1_Mean', '2_Mean', '3_Mean', 'Eolica_Mean', 'Nuclear_Mean', 'Carvao_Mean', 'CCombinado_Mean', 'Hidro_Mean', 'IntInter_Mean', 'Solar_Mean'], color='PRECO_ES')

fig.update_layout(width=2000, height=2500)

fig.show()

Then one would get the following (note that it still continues, but as it doesn’t fit the whole screen it is smaller on the screencapture)

enter image description here

Then, if one hovers on top of the visualization, there’s a specific button on the top right corner to download the image with the resolution defined previously.

enter image description here

Answered By: Gonçalo Peres