Widgets
Import the necessary packages for adding widgets.
In [1]:
Copied!
import thinkgreen
import pandas as pd
import numpy as np
import ipywidgets as widgets
from ipywidgets import DOMWidget
import matplotlib.pyplot as plt
import thinkgreen
import pandas as pd
import numpy as np
import ipywidgets as widgets
from ipywidgets import DOMWidget
import matplotlib.pyplot as plt
Display the map.
In [2]:
Copied!
m = thinkgreen.Map()
m
m = thinkgreen.Map()
m
Out[2]:
Map(center=[20, 0], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_text…
Add a dropdown menu to be able to change between graphs to display on the map.
In [3]:
Copied!
m.add_chart()
m.add_chart()
Create a bar chart.
In [4]:
Copied!
bar = m.add_bar(x=[1,2,3,4], y=[1,2,3,4])
bar = m.add_bar(x=[1,2,3,4], y=[1,2,3,4])
Add the bar chart to the map and specify the position.
In [5]:
Copied!
plt.style.use('_mpl-gallery')
x=[1,2,3,4]
y=[1,2,3,4]
# plot
fig, ax = plt.subplots()
ax.bar(x, y, width=1, edgecolor="white", linewidth=0.7)
ax.set(xlabel='x', ylabel='y', title='Bar Graph')
plt.show()
plt.style.use('_mpl-gallery')
x=[1,2,3,4]
y=[1,2,3,4]
# plot
fig, ax = plt.subplots()
ax.bar(x, y, width=1, edgecolor="white", linewidth=0.7)
ax.set(xlabel='x', ylabel='y', title='Bar Graph')
plt.show()
In [6]:
Copied!
m.add_widget(fig, position='bottomright')
m.add_widget(fig, position='bottomright')
Create a pie chart.
In [7]:
Copied!
pie = m.add_pie(x=[1,2,3,4])
pie = m.add_pie(x=[1,2,3,4])
Create a line chart.
In [8]:
Copied!
plot = m.add_plot(x=[1,2,3,4], y=[1,2,3,4])
plot = m.add_plot(x=[1,2,3,4], y=[1,2,3,4])
Last update:
2023-05-11