Folium map issue in PyCharm - python-3.x

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.

Related

Counting ipywidgets Intslider steps in Jupyter notebook

I am using the IntSlider() method from the ipywidgets() class to visualize and record the count for each step of a parameter in a seaborn Kdeplot(). Any quick fix is deeply appreciated. Thanks
import ipywidgets as widgets
from ipywidgets import Play
from IPython.display import display
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
cars = sns.load_dataset('mpg')
#widgets.interact(bw=(.1,5,.1))
def bandwidth(bw=0):
sns.kdeplot(cars.horsepower,lw=3,fill=True,bw_adjust=bw)
plt.xlim(-20,200)
plt.ylim(0, 0.04);
The widgets work well, but I need a way to record/capture the count (Good and Bad) of each step move in the slider; hopefully get the data in a list or table.

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

Attempting to convert an image to grayscale, or better, binary

My basic plan here is to create an image recognition software that tracks the size of different bubbles. I basically have a compilation of pictures that constitute a video. I have it working as of right now using PIMS to import the files I need and place them into an array (rawframes). I can print my picture.
import numpy as np
import pandas as pd
import pims
from pims import pipeline
import trackpy as tp
import os
import matplotlib as mpl
import matplotlib.pyplot as plt
#pipeline
def binary(frame):
return frame[:, :, 1]
id_example = 1
rawframes = pims.ImageSequence(os.path.join('BubbleSize/90FoamQuality/DryFoams', 'T20190411_002_ (*).jpg'), process_func=binary)
plt.imshow(rawframes[id_example])
What I am trying to do here is convert the images from regular into black and white. I have not used many of the things I imported yet I know, this is a very preliminary step.
However, below is a before and after image comparison. Can someone help me out or walk me through these steps here? I get lost when it comes to filtering the images through python.
edit --> when I change my pipeline function to the below, I get the same green image
edit2 --> printing frame.shape and frame.dtype in binary pipeline respectively

folium map not showing datbricks python

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

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