Plotly not showing graphs in pycharm - python

Iplot is not showing any output in pycharm and neither does it give any errorHere is the code I wrote

Related

How to display plotly as svg in GitHub and interactive plotly while in local?

My goal is to display plotly charts in GitHub (interactive or not). The reason that I switch to Plotly instead of using matplotlib.pyplot or pandas.Series.plot is that it offers you interactive charts.
However, after pushing the .ipynb file to GitHub. I noticed that the charts are not showing up.
What I've tried:
# fix plotly is not showing in github.
# if you want to have interactive plotly, use `fig.show("notebook_connected")`
import plotly.io as pio
pio.renderers.default = "svg"
The problem is that the charts become not interactive even in local.
Changing it to pio.renderers.default = "svg+notebook", the charts will be interactive in local. But it won't show in GitHub.

Plotly maps not showing in Jupyter Notebook in VS Code

stacks!
I'm trying to plot a graph using plotly, in Python. Specifically:
Plot: Maps, Bubblemaps, Choropleth..
Python: 3.9.6
Plotly: 4.01
Jupyter Notebook: 7.26
Env Manager: miniconda3
IDE: Ms. Visual Studio Code
I tried to run a code like this:
import plotly
import plotly.offline as pyo
pyo.init_notebook_mode()
import plotly.graph_objs as go
import plotly.express as ex
df = ex.data.gapminder().query("year==2007")
fig = ex.choropleth(df, locations="iso_alpha",
color="lifeExp", # lifeExp is a column of gapminder
hover_name="country", # column to add to hover information
color_continuous_scale=ex.colors.sequential.Plasma)
which is not my project code, just the example code of Plotly Map that I found on Plotly website (https://plotly.com/python/choropleth-maps/), but it's not showing anything.
P.S: I've tried to install plotly Jupyterlab dependencies from conda, i've also tried to use offline plotly but still nothing comes up. (Only the plot canvas and legend, the map is missing). Although, when I tried to make a bar chart it works. Help me masters!!!!!

Matplotlib notebook magic in Jupyter notebook partial plot

The first command in my Jupyter notebook is the %matplotlib notebook. This has been working fine but curiously the figures being drawn today are only partial plots. (The inline option without interactivity display complete plots).
When I pan, I can see more sections of the image.
I would like to see the entire plot and I am not sure what has caused this change in display
When image is first displayed it appears like this:
Image created upon running the cell
After panning it appears like this:
New section of image displayed upon panning
NOTE: This started to occur after updating to Matplotlib version 3.3.0.
For the current time I have reverted to Matplotlib version 3.1.0. But if the latest has some dependencies that I am missing which is causing the issue, I would like to learn how to figure those out.
I do not receive any errors or warnings upon import matplotlib or pyplot when working with 3.3.0

Save Jupyter Notebook with Plotly Express widgets displaying

I have a Jupyter notebook (python) where I used plotly express to plot in the notebook for analysis purposes.
I want to share this notebook with non-coders, and have the interactive visuals be available still - but it does not seem to work.
I tried following recommendations made here but even after saving widgets state and using nbconvert, when I open the new HTML file, the visuals are not available.
A sample line of plotting can be seen below:
import plotly_express as px
fig = px.scatter(
df,
x='size',
y='size_y',
color='clients',
hover_data=['id'],
marginal_y="histogram",
marginal_x="histogram"
)
fig.show()
After running plotly.offline.init_notebook_mode() in a cell,
you can export the notebook with full interactivity via the file menu:
File --> Export Notebook as... --> Export Notebook to HTML.
I was having similar issues but with JupyterLab. Followed the instructions here: https://plot.ly/python/renderers/ .
import plotly.io as pio
pio.renderers.keys()
I had to add the following snippet to my script:
import plotly.io as pio
pio.renderers.default = 'jupyterlab'
Exporting as HTML after that worked for me. You can read "Overriding the default renderer".
I suppose you would need
pio.renderers.default = 'notebook'
You can specify the default renderers from plotly with:
import plotly.io as pio
pio.renderers.default = 'pdf'
or when displaying the images with:
fig.show(renderer="pdf")
The 2 choices for you are:
'notebook': work well with jupyter notebook;
'pdf': perfect when using nbconvert to convert to HTML or LATEX
You can also join the 2 with "notebook+pdf" so you have iterative plots when running the notebook and static images when converting with nbconvert.
I just had a problem that resulted in this error message.
nbconvert/filters/widgetsdatatypefilter.py:69: UserWarning: Your element with mimetype(s) dict_keys(['application/vnd.plotly.v1+json']) is not able to be represented.
warn("Your element with mimetype(s) {mimetypes}"
Google brought me here, but I could not find a solution from the answers above.
I'm sharing the setup which caused my problem and the solution.
I was running the notebook in VS Code and then on the command line using: jupyter nbconvert
To solve it, I had to start jupyter lab and then run it and save it before running nbconvert.

Pycharm Jupyter Interactive Matplotlib

Interactive matplotlib plotting is already a thing, but does not work properly in Pycharm, when used within a jupyter notebook.
The %matplotlib notebook does not work (throws no error, but I get <IPython ... JavaScript object> instead of a plot. If I plot normally (also with or without plt.show()) I just get a png and cannot interact in any way (even if, e.g., sliders are visible).
I couldn't find any answers elsewhere to this exact problem. It might be working in the browser version of jupyter, but I would like to stick to using PyCharm.
Pycharm v 2017.3 Community Edition
You can try:
import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
Instead of importing only the peplos.
It's a trick I found on forum of Jetbrains
https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000736584-SciView-in-PyCharm-2017-3-reduces-functionality-of-Matplotlib It works for me. With this, you skip actually the Sciview and plot in a normal matplotlib window

Categories