Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly chart is not displayed in PyCharm

How can I display interactive plotly graphs in Pycharm? I run the following code:

import plotly.offline as py
import plotly.graph_objs as go

py.init_notebook_mode(connected=True)

data = [go.Bar(
    x=['giraffes', 'orangutans', 'monkeys'],
    y=[20, 14, 23]
)]

py.iplot(data, filename="barplot")

The result in PyCharm is a blank field: Plotly result in Pycharm

In Jupyter Notebook this code gives a (proper) interactive chart as the result.

Update: Answers from Embed Plotly HTML in PyCharm IDE don't work for me. When I use the plot() function (instead of the iplot()) it exports the chart into separate file and open a browser in a new window. The output in notebook is the filename of the generated chart. I want to include the chart into notebook and use it interactively, like in Jupyter Notebook. That answers are only about exporting the chart into separate html file.

like image 876
wind Avatar asked May 09 '18 09:05

wind


People also ask

Can you use plotly in Pycharm?

The best way to create and view Plotly Figures in PyCharm is using Jupyter Notebooks instead of regular Python Files. To create a Jupyter Notebook in Pycharm, Select File -> New and Select New File. Add the filename ending with . ipynb extension.

How can plotly visualizations be displayed?

In general, there are five different approaches you can take in order to display plotly figures: Using the renderers framework in the context of a script or notebook (the main topic of this page) Using Dash in a web app context. Using a FigureWidget rather than a Figure in an ipywidgets context.

How do I download plotly in Pycharm?

In Pycharm you have to download it. Go to File --> Settings -->Project --> Project Interpreter --> on the plus right site--> search for your module and download it! Thats it!!

How do you insert a plotly graph?

To share a plot from the Chart Studio Workspace, click 'Share' button on the left-hand side after saving the plot. The Share modal will pop-up and display a link under the 'Embed' tab. You can then copy and paste this link to your website. You have the option of embedding your plot as an HTML snippet or iframe.


1 Answers

jayBana's answer is correct, but if you want to keep using .py scripts in PyCharm, you can simply set default renderer to 'browser' to get interactive plotly graphs:

import plotly.io as pio
pio.renderers.default = "browser"

as described here: https://plot.ly/python/renderers/

like image 87
oy321 Avatar answered Sep 19 '22 17:09

oy321