Plotly graph shows a blank space on GitHub - python-3.x

I am using Plotly to make graphs in my IPython notebook. I am able to view graphs on my IPython notebook when I upload them on GitHub they are displayed as blank spaces.
I read on the web that Plotly currently does not support iframes and hence the issue, but is there a workaround?
Here's the link to my GitHub Ipython notebook:
https://github.com/dhavalbhinde/bhinde_dhaval_spring2017/blob/master/Finals/Analysis%203.ipynb
Please, can someone advice how should I handle them?

I found a way to show Plotly plots on Github. They aren’t interactive anymore but it’s better than nothing.
First
import plotly.io as pio
pio.renderers
you can see the list of available renders.
*if you get an error on this step you can simply just install orca:
conda install -c plotly plotly-orca
and then there are 2 possible ways.
you can pass "svg" to .show() like this:
fig = px.scatter_3d(iris, x=transformed_iris['component1'], y=transformed_iris['component2'], z=transformed_iris['component3'],color='species')
fig.show(renderer="svg")
or you can set the pio.renderers.default to svg:
pio.renderers.default = "svg"

Import these and this and it will work :
from plotly.offline import plot, iplot, init_notebook_mode
import plotly.graph_objs as go
init_notebook_mode(connected=True)

Related

matplotlib.plot doesn't show any image or plot without any error

I'm trying to show some images on VScode in Ubuntu, but matplotlib doesn't work. For example, even the most simple code such as:
import matplotlib.pyplot as plt
s_in = plt.imread("/media/aro/New Volume/Super resolution dataset/set5/Test/BSDS100/3096.png")
plt.imshow(s_in)
plt.show()
is not working, and it doesn't show any errors or warnings. What should I do?
In case anybody has got the same problem as mine. The error was because of the backend. So I had to change it. the only backend that worked for me was WebAgg.
Just add the following code at the beginning of your code.
import matplotlib.pyplot as plt
plt.switch_backend('WebAgg')

Cannot import bokeh built in themes from bokeh.themes

I am trying to set the theme for bokeh plots on jupyter lab.
To do so I am following the official docs, copying the exact code from https://docs.bokeh.org/en/latest/docs/reference/themes.html.
However, I get an error cannot import name 'built_in_themes'.
I assume the default themes location changed, but can't seem to find anything else besides the said page documenting bokeh.themes.
I assume the default themes location changed
No, it has only ever been in the same location since it was added in version 1.0. The explanation is almost certainly that the version you are using is older than that.
As bigreddot said, same location.
Check your Bokeh version:
$ python3.7
>>> import sys
>>> print(sys.version)
>>> import bokeh
>>> print(bokeh.__version__)
Or via jupyter notebook:
import numpy as np
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
Following the example here provided, the output should look like this:
Maybe you are just working in an environment with an older version.

How to get plotly graphs within jupyter notebook?

I am trying to create plotly bar graphs offline within Jupyter notebook. But I am getting the below error message. I am using x and y-axis from the data frame called train. X variable called Sex(Male or female) and Y variable called Survived (1 or 0)
Error message
"PlotlyError: Because you didn't supply a 'file_id' in the call, we're assuming you're trying to snag a figure from a url. You supplied the url, '', we expected it to start with 'https://plot.ly'.
Run help on this function for more information."
import plotly
from plotly.graph_objs import Bar, Scatter, Figure, Layout
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
from plotly.graph_objs import *
import numpy as np
data = [go.Bar(x=train.Sex,
y=train.Survived)]
py.iplot(data, filename='jupyter-basic_bar')
Any suggestions on how to get graphs within Jupyter notebook offline?
Change the line: py.iplot(data, filename='jupyter-basic_bar')
to iplot(data)
Example:

Customized matplotlib style with matplotlibrc doesn't load

I customized my own matplotlib style with matplotibrc by using the commands:
plt.style.reload_library()
plt.style.available
I was able to retreive my cumstomized style. However, when trying to load it with the command:
import matplotlib
#matplotlib.use('TkAgg')
matplotlib.rcParams["backend"] = "TkAgg"
import matplotlib.pyplot as plt
plt.style.use('MyCustomedStyle')
It's not being loaded. As you see, I have also tried to change the backend to use TkAgg for an interactive session, since I want to have it printed out on the screen.
I'm not getting any error messages. Still, however, it is not changing to my customized style.
I have also tried the command:
plt.rcParams.update(plt.rcParamsDefault)
%matplotlib inline
What am I doing wrong?

Update a Bokeh Span with an interact element in Jupyter notebook

I am trying to make a span in bokeh using jupyter widgets.
from ipywidgets import interact
import numpy as np
from scipy.stats import norm
from bokeh.sampledata.daylight import daylight_warsaw_2013
from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import figure
from bokeh.models import Span
output_notebook()
p = figure()
x_axis = np.arange(-10, 10, 0.001)
# Mean = 0, SD = 2.
y_axis = norm.pdf(x_axis,0,2)
p.line(x_axis, y_axis, line_dash='solid', line_width=2)
cutoff = Span(location=1,
dimension='height', line_color='green',
line_dash='dashed', line_width=2)
p.add_layout(cutoff)
show(p, notebook_handle=True)
def update(new_cutoff_location):
cutoff.location = new_cutoff_location
push_notebook()
interact(update, new_cutoff_location = 1.0)
When I run this code I get ValueError: PATCH-DOC message requires at least one event at push_notebook(). I suspect this indicates that the update to cutoff.location isn't getting detected, so it it looks as if there are no changes to send. Passing the handle doesn't seem to make a difference. Looking at the sample code in this github issue, it looks like there used to be an set method on span elements, but there doesn't appear to be one on my span element cutoff. Maybe there is a different function I am supposed to call to register the change?
I'm on bokeh 0.12.11 with jupyter 1.0.0, jupyter-client 5.1.0, jupyter-console 5.2.0, jupyter-core 4.4.0
This appears to be a regression in Bokeh 0.12.11. Your code works with version 0.12.10 so the immediate workaround is to downgrade. I've made GitHub issue here that you can follow. We will issue a new point release with a fix ASAP.
UPDATE: The issue is now fixed in recent versions of Bokeh

Resources