folium map not showing datbricks python - databricks

I am working on Databricks and have a folium map:
import geopandas as gpd
import matplotlib as plt
import os
import folium
from IPython.display import display
map_osm = folium.Map(location=[45.5236, -122.6750])
map_osm
I get the following:
<folium.folium.Map at 0x7f9978eec748>
I tried Folium map not displaying to no avail.
Any suggestions

Try this
import folium
import webbrowser
map_osm = folium.Map(location=[45.5236, -122.6750])
map_osm.save('map.html')
webbrowser.open('map.html')
The output of the function is a HTML file and Python IDLE fails to render the html document unless explicitly called. You can also try using the same code on Jupyter notebook which runs on a browser and can render html map at ease.

Turning the map into HTML then displaying worked for me in Databricks using Python 3.5
world_map = folium.Map()
html_map = world_map._repr_html_()
displayHTML(html_map)
The original answer came from Databricks forums by ShumZZ: https://forums.databricks.com/questions/444/how-to-create-maps-in-databricks.html

Related

can anyone explain why this code regarding plotly libraries worked well in jupyter notebook but showed an error when i ran it in intellij

I saw this video on youtube : using plotting a dataframe using iplot method imported from plotly.offline module.
I ran this code on intellij but got an error saying :
latin-1' codec can't encode characters in position 0-9: ordinal not in range(256)
i looked up for a solution but couldn't anything. Then i ran this code in jupyter notebook and it worked just fine
can anyone explain this.
source code -
import pandas as pd
import numpy as np
import chart_studio.plotly as py
from plotly.offline import *
import cufflinks as cf
init_notebook_mode(connected=True)
cf.go_offline()
df=pd.DataFrame(np.random.randn(50,4),columns=['a','b','c','d'])
df.iplot()

Is there anyway to call PubChem API In python?

I have been using PubChem API to convert Chemical smiles to the structure but still have an error.
Here is my google colab I try with PIL image plus TKinter
https://colab.research.google.com/drive/1TE9WxXwaWKSLQzKRQoNlWFqztVSoIxB7
My desired output should be in structure format like this
https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/O=C(N1C=CN=C1)N2C=CN=C2/PNG?record_type=2d&image_size=large
Download and display in a Jupyter Notebook
from urllib.request import urlretrieve
from IPython.display import Image
smiles = 'NC1=NC(C)=C(C2=CC=C(S(=O)(C)=O)C(F)=C2)S1'
urlretrieve('https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/'+smiles+'/PNG', 'smi_pic.png')
p = Image(filename='smi_pic.png')
p
Output

Folium map issue in PyCharm

I am using Pycharm and the folium maps are not being displayed. My code is as follows:
import folium
from folium import plugins
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from IPython.core.display import display, HTML
m = folium.Map([52.5, 2], zoom_start=5.5)
display(m)
But I am able to save it as html and it is correctly displayed in html.
m.save('aee.html')
You can't open the map directly in pycharm.
Yet, as you stated you can make an HTML File of it.
Here's a little function to auto-open it in browser:
def auto_open(path):
html_page = f'{path}'
f_map.save(html_page)
# open in browser.
new = 2
webbrowser.open(html_page, new=new)
I'm using fuliom like this in a Django app, it's quite useful as render tool as well.
Folium also provides ability to save the map to images, check it out.

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.

Plotly graph shows a blank space on GitHub

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)

Resources