As per the question in the link below:
Set map id using folium?
df = pd.read_csv("gc_geo.csv")
fgc=folium.FeatureGroup(name="Gigant",overlay=True)
fgc._name = "Gigak"
fgc._id= "1"
I am wondering about a similar option for any Folium map element.
The code I prepared above seems not to work.
The console is fine, but nothing changes, as tried in VSC (see image below).
Is there any workaround to set my folium map elements with customized icons
Related
I have a GeoJSON file that contains country/empire borders in the year 1800. I am trying to depict this using Folium. I would like to have the name of each country/empire to be displayed (text) within each country/empire region in the map (basically the same as what is shown on "normal" present-day maps, but I can't just overlay this over present-day maps because the borders have changed over time). The GeoJSON file has a field that contains the name of each respective country/border, but I don't know how to display this on the map.
I do not want this to be a tooltip / popup. Instead, I want the text displayed in the base map, viewable without hovering your mouse over the map or clicking on anything.
I have seen some similar questions, and the responses are essentially to use a DivIcon. But this seems like a clunky solution and not very clean when dealing with a large map and many, many labels.
Is there a good way to display this? I looked in the Folium documentation and didn't see any arguments in the GeoJson class that seems like it would do this. (For example, it would be nice to tell Folium to automatically add 'region' labels, and to use a given field as the source of the labels).
Thanks!
I have linked the x axis of my bokeh graphs together by simply sharing the same x_range:
graph2.x_range = graph1.x_range
When I zoom-in/out or change the x-axis of one graph in any way, the other graph adjust with it. I really like this functionality.
However, when I embed the bokeh graphs in an html template they are not connected anymore.
script, div = components(graphs).
The components function returns a script that contains the data for your plot and provides a target div to display the plot view.
I added script and div in the placeholders of my html template, which is then loaded with Flask.
Everything works fine, but the graphs are not connected anymore.
It looks like the graps are embedded separately and therefore they cannot be linked together. I wonder if there is a method to do this.
If anyone has had this issue before, pls help :)
I used this documentation:
https://docs.bokeh.org/en/2.4.1/docs/user_guide/embed.html
I'm relatively new to python and this is the first project that I'm working on. I'm trying to plot a simple multi line chart using altair onto a folium marker's popup. I followed the examples on this page https://github.com/python-visualization/folium/blob/master/examples/Popups.ipynb. But when I click on the marker, it's just plain white. The map and markers are plotted fine except the popup.
This is what my whole dataset looks like :
Here is the code:
import pandas as pd
import folium
import altair as alt
import json
chart = alt.Chart(df).mark_line().encode(
x='index',
y='Ambala',
color='Variable')
chart_2 = json.loads(chart.to_json())
m = folium.Map([30,-80],zoom_start=2)
popup = folium.Popup(max_width=650)
folium.Vega(chart_2, height=350, width=650).add_to(popup)
folium.Marker([30, -80], popup=popup).add_to(m)
m
Note that this just a sample of code. I'll be implementing this on a larger scale in my project.
I tried to plot a visualization (which I found here : https://github.com/python-visualization/folium/blob/master/examples/data/vis1.json) and this seemed to work fine. I just don't understand why the same code works for their plot but not for mine even though altair produces a fine looking chart from my code. Sorry if this is sounds silly, I'm still a beginner and python is my first language. Thanks
If you want to use an Altair chart inside a folium map, you need to use a VegaLite object instead of a Vega object. You just need to change the line with the Vega object like that : folium.features.VegaLite(chart_2, height=350, width=650).add_to(popup)
I have RangeSlider defined as follows,
slider = RangeSlider(start=0, end=5, value=(0,1), step=1, title="Time")
Is there a way to change the output of the slider so that instead of getting the values 0 to 5, I am able to 'map' these values into some other labels. For instance, whenever the range is 0...4, I get instead t0...t4.
I have not been able to find any information in the bokeh documentation to do this. I am just wondering whether it is at all possible.
I would appear that this is possible but the answer is not simple, and requires going deep into bokeh and javascript. I have found a some mention of this possibility in this video (see video # min 25:30) which lead me to this file in the bokeh repo.
I'm fairly new to folium so this might be a bit noobish but I'm currently trying to plot several heatmaps of different data-points and add the ability to switch between the heatmaps all on the same plot. So for example I have such:
# The base map
hmap = folium.Map(location=[38.908111, -77.008871], tiles="Stamen Terrain", zoom_start=12)
# And each layer
# Homicide
HeatMap(list(zip(crime_homicide.LATITUDE.values, crime_homicide.LONGITUDE.values))).add_to(folium.FeatureGroup(name='Homicides').add_to(hmap))
# Robbery
HeatMap(list(zip(crime_robbery.LATITUDE.values, crime_robbery.LONGITUDE.values))).add_to(folium.FeatureGroup(name='Robbery').add_to(hmap))
# Assault
HeatMap(list(zip(crime_assault.LATITUDE.values, crime_assault.LONGITUDE.values))).add_to(folium.FeatureGroup(name='Assault').add_to(hmap))
folium.LayerControl(collapsed=False).add_to(hmap)
folium.GeoJson(dc_shape).add_to(hmap)
I tried using folium's FeatureGroup functionality but it looks like thats only specific markers as opposed to whole maps. Is there a way to switch between different maps if they're all heatmaps?
Your code seems fine.
Try this -
hmap.add_child
Or you can try heatmapwithtime as well, specifying different metrics which you can adjust in realtime to see different heatmaps.
But,FeatureGroup() will not seem to work with HeatMapWithTime and adding layers directly to the heatmap results in multiple time sliders on the side when there should be only one (common) time slider for all added layers.
So if you want to have a single control you'll have to put all your data in a single geojson and use that.
Why do you add a feature group? If you want to be able to select which instance of HeatMapWithTime you want to display, you can add both add them to the map, and they should both turn up in layer control.
m = Map()
HeatMapWithTime(data1).add_to(m)
HeatMapWithTime(data2).add_to(m)
FYI, a feature group is meant to group items and display them together. The items themselves don't get added to the map directly. For example:
fg = FeatureGroup().add_to(m)
fg.add_child(Item1)
fg.add_child(Item2)
Also this is the link, might help you :)
https://python-visualization.github.io/folium/plugins.html