Пример #1
0
def plot_flight(lons, lats):
    """plot the igc data to a map"""
    data = [Scattergeo(lon=lons, lat=lats)]
    my_layout = Layout(title='IGC flight data')

    fig = {'data': data, 'layout': my_layout}
    offline.plot(fig, filename='IGC_flight_data.html')
Пример #2
0
#The indent=4 arguement tells dump() to format the data using indent 

json.dump(eq_data,outfile,indent=4)

list_of_eqs = eq_data['features']
mags, lons, lats = [], [], []

for eq in list_of_eqs:
    mag = eq['properties']['mag']
    lon = eq['geometry']['coordinates'][0]
    lat = eq['geometry']['coordinates'][1]
    mags.append(mag)
    lons.append(lon)
    lats.append(lat)

print(mags[:10])
print(lons[:10])
print(lats[:10])

from plotly.graph_objs import Scattergeo, Layout
from plotly import offline

data = [Scattergeo(lon=lons, lat=lats)]

my_layout = Layout(title="Global Earthquakes")

fig = {'data': data, 'layout': my_layout}

offline.plot(fig,filename='global_earthquakes.html')

Пример #3
0
fire_data = json.load(infile)

json.dump(fire_data, outfile, indent=4)

datalons, datalats, databright = [], [], []
for x in fire_data:
    lon = x["logitude"]
    lat = x["latitude"]
    bright = x["brightness"]
    if bright > 450:
        databright.append(bright)
        datalons.append(lon)
        datalats.append(lat)

list_of_fire = fire_data['features']

brightness, longitude, latitude = [], [], []

from plotly.graph_objs import Scattergeo, Layout
from plotly import offline

data = [Scattergeo(longitude=lons, latitude=lats)]

my_layout = Layout(title="US Fires from 9-1-2020 to 9-13-2020")

fig = {"data": data, 'layout': my_layout}

offline.plot(fig, filename='US_fires_9_1.html')

print(fires_data['features'][0]['properties']['brightness'])
Пример #4
0
print(len(all_eq_dicts))

# Extract the mag of the earthquakes.

mags = [eq_dict["properties"]["mag"] for eq_dict in all_eq_dicts]

mags = [mag if mag >= 0 else -1 * mag for mag in mags]

hover_text = [eq_dict["properties"]["title"] for eq_dict in all_eq_dicts]
# Extract the longtitude and latitudes of earthquakes. geodata are in (long, latitude) format

longt = [eq_dict["geometry"]["coordinates"][0] for eq_dict in all_eq_dicts]
latit = [eq_dict["geometry"]["coordinates"][1] for eq_dict in all_eq_dicts]

# Map the earthquakes.
data = [Scattergeo(lon=longt, lat=latit)]
# Another way to represent data

data_2 = [
    {
        "type": "scattergeo",
        "lon": longt,
        "lat": latit,
        "text" : hover_text,
        "marker": {
            "size": [4 * mag for mag in mags],
            "color": mags,
            "colorscale": "Rainbow",
            "reversescale": False,
            "colorbar": {"title": "Magnitude"},
        }, 
Пример #5
0
list_of_eqs = eq_data["features"]

mags = []
lons = []
lats = []

for eq in list_of_eqs:
    mag = eq["properties"]["mag"]
    lon = eq["geometry"]["coordinates"][0]
    lat = eq["geometry"]["coordinates"][1]

    mags.append(mag)
    lons.append(lon)
    lats.append(lat)

print(mags[:10])  # from zero to tenth element, 0 to 9, called list slicing
print(lons[:10])
print(lats[:10])
# above basically has eq as the first part of statement, eq_data['features'], for statement adds vars as second part

# graph
from plotly.graph_objs import Scattergeo, Layout  # Remeber case sensitive
from plotly import offline

data = [Scattergeo(lon=lons, lat=lats)]  # requires list of a and list of b
my_layout = Layout(title="Global Earthquakes")

fig = {"data": data, "layout": my_layout}

offline.plot(fig, filename="global_earthquakes.html")
    json.dump(all_eq_data, f, indent=4)

#Make a list of all earthquakes.
all_eq_dicts = all_eq_data['features']

mags, lons, lats = [], [], []
for eq_dict in all_eq_dicts:
    mag = eq_dict['properties']['mag']
    lon = eq_dict['geometry']['coordinates'][0]
    lat = eq_dict['geometry']['coordinates'][1]
    mags.append(mag)
    lons.append(lon)
    lats.append(lat)

print(mags[:10])
print(lons[:5])
print(lats[:5])

#Map the earthquakes.
data = [
    Scattergeo(lon=lons, lat=lats)
]  #Define a list called data and create Scattergeo module inside the list.
my_layout = Layout(title='Global earthquakes')  #Give chart a title.

fig = {
    'data': data,
    'layout': my_layout
}  #Create dictionary called fig that contains data and layout.
offline.plot(fig, filename='global_earthquakes.html'
             )  #Plot() function with a descriptive name for the output.
Пример #7
0
with open(filename, 'r') as f:
    all_eq_data = json.load(f)

all_eq_dicts = all_eq_data['features']

mags = [mag['properties']['mag'] for mag in all_eq_dicts]
lons = [lon['geometry']['coordinates'][0] for lon in all_eq_dicts]
lats = [lat['geometry']['coordinates'][1] for lat in all_eq_dicts]
hover_texts = [
    hover_text['properties']['title'] for hover_text in all_eq_dicts
]

# Map the earthquakes.
data = [
    Scattergeo(lon=lons,
               lat=lats,
               text=hover_texts,
               marker={
                   'size': [5 * mag for mag in mags],
                   'color': mags,
                   'colorscale': 'Viridis',
                   'reversescale': True,
                   'colorbar': {
                       'title': 'Magnitude'
                   }
               })
]
my_layout = Layout(title=all_eq_data['metadata']['title'])

fig = {'data': data, 'layout': my_layout}
offline.plot(fig, filename='output-files/global_earthquakes.html')
Пример #8
0
        lats.append(lat)

# print(brights[:10])
# print(lons[:10])
# print(lats[:10])

from plotly.graph_objs import Scattergeo, Layout
from plotly import offline

data = [{
    "type": "scattergeo",
    "lon": lons,
    "lat": lats,
    "marker": {
        "size": [0.02 * brightness for brightness in brights],
        "color": brights,
        "colorscale": "Viridis",
        "reversescale": True,
        "colorbar": {
            "title": "Brightness"
        },
    },
}]
Scattergeo(lon=lons, lat=lats)  # taking scatterplots and putting on a map

my_layout = Layout(title="Prominent US Fires")  # give layout for ^

fig = {"data": data, "layout": my_layout}

offline.plot(fig, filename="us_fires.html")
with open(filename) as f:
    reader = csv.reader(f)
    column_header = next(reader)
    print(column_header)

    for rec in reader:
        lons.append(rec[1])
        lats.append(rec[0])
        bright_ti4.append(rec[2])
        hover_texts.append(rec[5])

    # Map the earthquakes.
data = [
    Scattergeo(
        lon=lons,
        lat=lats,
        text=['Reported on : ' + hover_text for hover_text in hover_texts],
        marker={
            'size': 2,
            'color': 'firebrick',
            'colorscale': 'Viridis',
            'reversescale': True,
            'colorbar': {
                'title': 'Magnitude'
            }
        })
]
my_layout = Layout(title='World Fires!!!')

fig = {'data': data, 'layout': my_layout}
offline.plot(fig, filename='output-files/world_fires.html')
Пример #10
0
list_of_eqs = []

list_of_eqs = eq_data["features"]

# print(list_of_eqs)

mags, longs, latds = [], [], []
# eq is already the sub 0 index value, so only
# properties and mag need to be indexed to get each eq magnitude
for eq in list_of_eqs:
    mag = eq["properties"]["mag"]
    long = eq["geometry"]["coordinates"][0]
    latd = eq["geometry"]["coordinates"][1]

    mags.append(mag)

    longs.append(long)

    latds.append(latd)

print(mags[:10])
print(longs[:10])
print(latds[:10])

data = [Scattergeo(lon=longs, lat=latds)]

my_layout = Layout(title="Global Earthquakes")

fig = {'data': data, 'layout': my_layout}

offline.plot(fig, filename="global_earth")
Пример #11
0
import chapter_sixteen.eq_explore_data

import json

from plotly.graph_objs import Scattergeo, Layout

from plotly import offline

from chapter_sixteen import eq_explore_data

my_data = [
    Scattergeo(lon=eq_explore_data.lons,
               lat=eq_explore_data.lats,
               text=eq_explore_data.hover_texts,
               marker={
                   'size': [5 * mag for mag in eq_explore_data.mags],
                   'color': eq_explore_data.mags,
                   'colorscale': 'Viridis',
                   'reversescale': True,
                   'colorbar': {
                       'title': 'Magnitude'
                   },
               })
]
my_layout = Layout(title='Global Earthquakes')

fig = {'data': my_data, 'layout': my_layout}
offline.plot(fig, filename='global_earthquakes.html')
Пример #12
0
#Escribiendo archivo JSON bien identado
output_filename = 'significant_month.geojson'
with open(output_filename, 'w') as f2:
    json.dump(load_all, f2, indent=4)

    #Revisando cuantos terremotos hay dentro
    registros_terremotos = load_all['features']
    print(f"cantidad de terremotos {len(registros_terremotos)}")

Magnitudes, longitudes, latitudes, hover_text = [], [], [], []
for Feature in registros_terremotos:
    Magnitudes.append(Feature['properties']['mag'])
    longitudes.append(Feature['geometry']['coordinates'][0])
    latitudes.append(Feature['geometry']['coordinates'][1])
    hover_text.append(Feature['properties']['title'])

print(Magnitudes[:10])
print(longitudes[:10])
print(latitudes[:10])

data = [Scattergeo(lon=longitudes, lat=latitudes)]

my_layout = Layout(title='Terremotos globales')
fig = {'data': data, 'layout': my_layout}
offline.plot(fig, filename='terremotos_globales.html')

#Imprimir escalas de colores diponibles

for key in colors.PLOTLY_SCALES.keys():
    print(key)
    brights.append(int(float(
        row[2])))  #for some reason doing just int() didn't work

#Print Values of First 10 in Each List
#print(brights[:10])
#print(lons[:10])
#print(lats[:10])

#Load Data to Create Plot of Fire Data
data = [
    Scattergeo(
        lon=lons,
        lat=lats,
        #Customize Markers
        marker=dict(
            color=brights,
            colorscale='Viridis',
            reversescale=True,
            line=dict(width=1, color='White'),
            size=12,
            #Customize Colorbar
            colorbar=dict(titleside="top", title='Brightness')))
]

#Create/Customize Plot Layout
my_layout = Layout(title="Australian Fires - January 2020",
                   geo=dict(
                       fitbounds="locations",
                       showland=True,
                       landcolor="rgb(229, 236, 246)",
                   ))