5

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.

Gonçalo Peres
  • 11,752
  • 3
  • 54
  • 83
Zues
  • 307
  • 5
  • 12
  • @Zeus one is able to do that with Plotly on VS Code. [See my answer](https://stackoverflow.com/a/74392447/7109869) on one way to do that. – Gonçalo Peres Nov 10 '22 at 19:54
  • This is not the same as resizing the view: I believe it changes the size of the figure, which is not the same (for example if you want to save the figure). Like several similar answers it doesn't even sound like a VScode related feature. – Vincenzooo Jan 11 '23 at 14:07
  • Does this answer your question? [VS Code and Jupyter Notebook - how to open large output in text editor?](https://stackoverflow.com/questions/68331861/vs-code-and-jupyter-notebook-how-to-open-large-output-in-text-editor) or https://stackoverflow.com/questions/68207737/jupyter-change-output-cell-size – Vincenzooo Jan 11 '23 at 14:08

5 Answers5

7

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.

Todd Miller
  • 189
  • 2
  • 9
  • this changes the matplotlib figure dpi and size. In some cases you want to maintain the size of the figure (e.g. to generate an image) but still show a reduced (or enlarged) figure in VScode output. – Vincenzooo Jan 11 '23 at 13:55
4

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.

downbydawn
  • 57
  • 1
  • 6
  • This changes the size of matplotlib figure, not of the VScode view (it is not the same thing, e.g. if you want to generate a figure). – Vincenzooo Jan 11 '23 at 13:57
2

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.

Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22
1

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

Gonçalo Peres
  • 11,752
  • 3
  • 54
  • 83
0

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

  • 1
    would you be able to add an example? What is the command which contains the x,y params? Are you referring to plt.plot (which is just one of the many ways to generate graphics) or something else? – Vincenzooo Jan 11 '23 at 13:56