Seite 1 von 1

Modul leaflet bzw. mplleaflet Karte schön bunt

Verfasst: Dienstag 26. März 2019, 21:12
von Strawk
Hallo Profis!

Kennt sich jemand mit dem Python-Modul leaflet bzw. mplleaflet aus? Läuft ganz gut. Problem: die Karte ist zwar sehr detailliert, mit Straßennamen und Gebäuden und so, aber alles in Grautönen. Kennt jemand einen Parameter, der die Karte schön farbig macht? Ich hatte das schon mal, daher weiß ich, dass das geht.

Grüße
Strawk
:?:

Re: Modul leaflet bzw. mplleaflet Karte schön bunt

Verfasst: Sonntag 31. März 2019, 15:01
von Strawk
Hallo!
24 h sind länsgt rum, dann kann ich ja wieder.
Mein GPX-Projekt geht weiter. Habe gestern den ganzen Tag versucht, etwas zustande zu bringen, wie ihr auf diesem Bild seht: https://ibb.co/qpPpJt0
Hier ist mein schwachsinniger Code dazu:

Code: Alles auswählen

def plot_trip(self, gpxdata):
        """
        creates a graphical plot of the whole trip
        """
        lat = self.df['lat']
        lon = self.df['lon']
        
        # x = (np.max(lat), lon[np.argmax(lat)])
        # y = (lat, lon)
        
        # plt.plot(y, x)
        # plt.plot(y)
        plt.plot(np.max(lat), lon[np.argmax(lat)], 'r')
        plt.plot(lat, lon)
        plt.show()
Und:

Code: Alles auswählen

def extremes(lon, lat):
    """ shows the nothernmost point of the track
    """
    
    # print(lat, lon)
    
    lat = np.array(lat)
    lon = np.array(lon)
    
    # print(lat, lon)
    
    north = (np.max(lat), lon[np.argmax(lat)])
    # north = (7)
    # print('here', north)
    plt.plot(north, 'ro')
    
    plt.show()
Ich brauche hierin dringend Hilfe!
Grüße
Strawk

Re: Modul leaflet bzw. mplleaflet Karte schön bunt

Verfasst: Montag 8. April 2019, 08:24
von Strawk
Hallo Nutzer!
Um nochmal auf das ursprüngliche Thema dieses Threads zurückzukommen: Es geht um den Einsatz der Python-Module:
mplleaflet
folium
matplotlib
Wenn ihr folgenden Code ausführt:

Code: Alles auswählen

 # -*- coding: utf-8 -*-
import os
import mplleaflet
import folium
import matplotlib.pyplot as plt

def show_on_map(lon, lat):
    """ shows the track or the like on a map
    """
    # htmlFilesPath = "results" # path where html-results are stored
    
    fig, ax = plt.subplots()
        
    ax.plot(
        lon,
        lat,
        color='darkorange',
        linewidth=5,
        alpha=0.5
    )
    sub = 10
    kw = {'color': 'deepskyblue', 'alpha': 0.8, 'scale': 10}
    ax.quiver(lon[::sub],
              lat[::sub],
              **kw)
    gj = mplleaflet.fig_to_geojson(fig=fig)
    lon, lat = lon[0], lat[0]
    zoom_start = 14
    m = folium.Map(
        location=[lat, lon],
        tiles='Cartodb Positron',
        zoom_start=zoom_start
    )
    line_string = gj['features'][0]
    gjson = folium.features.GeoJson(line_string)
    
    m.add_child(gjson)
    m.save(os.path.join('results', 'Folium_and_mplleaflet_0.html')) 
und dann
diese Funktion ausführt mit:

Code: Alles auswählen

 mytrack.show_on_map()
        webbrowser.open(os.path.join(htmlFilesPath+htmlFileName)) 
wobei lon und lat Breiten- und Längengrade sind, dann sollte sich der Standardbrowser öffnen und den Umriss der Strecke auf einer Karte darstellen. Problem nun: Die Karte ist ausgegraut, siehe
https://ibb.co/WcJ6Vwc
Kennt jemand die benutzten Module so gut, dass er mir sagen kann, wie die Karte farbig dargestellt werden kann. Möglicherweise ist das ja nur ein einziger Parameter.
Grüße
Strawk

Re: Modul leaflet bzw. mplleaflet Karte schön bunt

Verfasst: Montag 8. April 2019, 12:10
von ThomasL
wenn ich diese Seite hier richtig interpretiere
https://python-graph-gallery.com/288-ma ... th-folium/
sollte es an dem Parameter tiles='Cartodb Positron' liegen.
Schon mal da was anderes probiert?

Re: Modul leaflet bzw. mplleaflet Karte schön bunt

Verfasst: Montag 8. April 2019, 17:23
von Strawk
Du, hör mal: Das klappt sehr gut und sieht absolut super aus. Wie eine farbig gedruckte Karte von früher; herrliche Optik, kann ich jedem nur empfehlen. :)

Code: Alles auswählen

m = folium.Map(
        location=[lat, lon],
        tiles='OpenStreetMap',
        zoom_start=zoom_start
    )
lautet das Zauberwort.
Grüße
Strawk