def create_multiple_pointers_2(): """ Uses the dataframe built in apply function. This is faster and should be used for large datasets. """ airports = vds.airports() airports = airports[:25] map_airports_2 = folium.Map(location=[38, -98], zoom_start=4) airports.apply(lambda row: folium.Marker(location=[row['latitude'], row['longitude']], popup=row['name']) .add_to(map_airports_2), axis=1) return map_airports_2
def create_multiple_pointers_1(): # fetch data using vega_datasets airports = vds.airports() airports = airports[:25] # create map map_airports = folium.Map(location=[38, -98], zoom_start=4) for (index, row) in airports.iterrows(): try: folium.Marker(location=[row.loc['latitude'], row.loc['longitude']], popup=row.loc['name'] + '' + row.loc['city'] + '' + row.loc['state'], tooltip='click!').add_to(map_airports) except Exception: print("ups") return map_airports
marker_cluster = MarkerCluster(markers=(marker6, marker7, marker8, marker9)) m.add_layer(marker_cluster); # display_map m # In[12] # Multiple Marker from ipyleaflet import Map, Marker # install vega_datasets first from python.org python package index from vega_datasets import data # airports dataframe using vega_datasets airports = data.airports() airports = airports[:25] # create map airports_map = Map(center=(-6.1753942, 106.827183), zoom=8) # plot airport locations for (index, row) in airports.iterrows(): marker = Marker(location=[row.loc['latitude'], row.loc['longitude']], title=row.loc['name'] + ' ' + row.loc['city'] + ' ' + row.loc['state']) airports_map.add_layer(marker) # display map airports_map # In[14]
# st.bar_chart() # *** SCATTER PLOT *** # example using altair cars = vds.cars() st.write(cars.head()) scatter = alt.Chart(cars).mark_circle().encode( x='Weight_in_lbs', y='Miles_per_Gallon').interactive() st.altair_chart(scatter) # *** OTHER CHARTS AND PLOTS *** # streamlit can display a number of other charts, images, etc. # *** MAP *** st.title('Map') airports = vds.airports()[['latitude', 'longitude']][0:100] st.map(airports) # *** SLIDER *** st.title('Slider') slider = st.slider(label='slider', min_value=0, max_value=10, value=5) st.write(slider, 'cubed is', slider * slider * slider) # *** CHECKBOX *** st.title('Checkbox') fig_map = plt.figure(figsize=(12, 8)) ax_map = fig_map.add_subplot(1, 1, 1, projection=ccrs.PlateCarree()) ax_map.set_global() if st.checkbox('land'): ax_map.add_feature(cfeature.LAND) if st.checkbox('ocean'): ax_map.add_feature(cfeature.OCEAN) if st.checkbox('coastline'): ax_map.add_feature(cfeature.COASTLINE)
def SwitchExample(argument): from vega_datasets import data switcher = {"Airports": data.airports(), "Cars": data.cars()} return switcher.get(argument, "Not found!")
def load_data(): return pd.concat((data.airports() for _ in range(100)))
@st.cache def select_rows(dataset, nrows): return dataset.head(nrows) @st.cache def describe(dataset): return dataset.describe() rows = st.slider("Rows", min_value=100, max_value=3300 * 100, step=10000) start_uncached = time() dataset_uncached = pd.concat((data.airports() for _ in range(100))) load_uncached = time() dataset_sample_uncached = dataset_uncached.head(rows) select_uncached = time() describe_uncached_dataset = dataset_sample_uncached.describe() finish_uncached = time() benchmark_uncached = ( f"Cached. Total: {finish_uncached - start_uncached:.2f}s" f" Load: {load_uncached - start_uncached:.2f}" f" Select: {select_uncached - load_uncached:.2f}" f" Describe: {finish_uncached - select_uncached:.2f}" ) st.text(benchmark_uncached) st.write(describe_uncached_dataset)
ax.add_feature(cfeature.BORDERS, linestyle=':') ax.add_feature(cfeature.LAKES, alpha=0.5) ax.add_feature(cfeature.RIVERS) ax.add_feature(cfeature.STATES) plt.show() # ~ #*********************************************************************** # ~ # AFFICHAGE AEROPORTS (VEGA_DATASETS) # ~ #*********************************************************************** import cartopy.crs as ccrs import cartopy.feature as cfeature import matplotlib.pyplot as plt from vega_datasets import data as vds airports = vds.airports() airports = airports.iloc[:10] plt.figure(figsize=(14, 14)) ax = plt.axes(projection=ccrs.PlateCarree()) # (x0, x1, y0, y1) ax.set_extent([-130, -60, 20, 55], ccrs.PlateCarree()) ax.add_feature(cfeature.STATES) ax.coastlines() for i in airports.itertuples(): ax.scatter(i.longitude, i.latitude, color='blue',
""" Locations of US Airports ======================== This is a layered geographic visualization that shows the positions of US airports on a background of US states. """ # category: case studies import altair as alt from vega_datasets import data airports = data.airports() states = alt.topo_feature(data.us_10m.url, feature='states') # US states background background = alt.Chart(states).mark_geoshape( fill='lightgray', stroke='white' ).properties( width=500, height=300 ).project('albersUsa') # airport positions on background points = alt.Chart(airports).mark_circle().encode( longitude='longitude:Q', latitude='latitude:Q', size=alt.value(10), color=alt.value('steelblue') ) background + points