0

I'm using PyCharm version 3.7. When I tried to open simple folium map I'm not getting any output. I tried something like this

import folium
import pandas as pd
import csv
dataframe=pd.read_csv("data1.txt")
Data=dataframe.to_csv("datacsv.csv")
Sampledata=pd.read_csv('datacsv.csv',delim_whitespace=True)
Temp=sampledata['Temp']
Lat=sampledata ['lat']
Lon=sampledata ['lon']
List=sampledata ['Temp'].values.tolist()
M=folium.Map(location=plot.Lat.mean(),plot.Lon.mean()],zoom_start=6)
HeatMap(List).add_to(M)
M.save("out.html")

This is my code...I'm getting error in temp , folium map is not displaying any output and html page showing a blank page.

I tried it Jupyter Notebook also but I realised that maps are not showing in my Jupyter and PyCharm.

How can I solve the issue?

1 Answer 1

3

I think the first port of call with this would be to check what your browser is telling you when you open your html file.

In the browser open the file you create and hit F12. This will open the "developer" window of the browser (should work in Edge and Chrome). Head to the console and any errors in the html will present here.

Next lets look at your code.

You seem to spend a bit of time getting the text file converted to csv. To troubleshoot, try converting this text file into csv another way. Try Excel if you can or your preferred spreadsheet program. Once you have a csv setup, test that this can be loaded in QGIS or another program (to make sure there no issues there).

If that all works, have a look at this simple working Heatmap script, see if you can gleam anything out of it.

import pandas as pd
from folium import plugins
from folium.plugins import HeatMap
import folium
import webbrowser

data = r'PATH TO YOUR CSV'
df = pd.read_csv(data, skiprows = 0)

print (df) ## Check your data is loading correctly
heat_df = df[['Y','X']] ## or df[['lat','long']] from your case

m = folium.Map(location = [0,0], zoom_start = 6, max_zoom = 10) ## Choose a location closer to home for you - you can add the "fancy" mean lat long once you have it working

HeatMap(heat_df,radius = 20, min_opacity = 0.5, max_val = 10, gradient={.25:'blue', .5: 'lime', .75:'yellow', 1:'red'}).add_to(m)
## breaking this down, the data is the heat_df, we set the HM radius to 20 units, we control the opacity and set the colour of the heatmap from green to red

m.save (r'c:\temp\example.html')
webbrowser.open(r'c:\temp\example.html')

Once you have a working example, you can tweak the code to be fancier and less "hands-on" with the data processing in the beginning.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.