|
|
|
"""durham_trees_analysis |
|
|
|
Automatically generated by Colaboratory. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/1OjlRC7F_UICGJM59jzSoy1o2crZxqXCl |
|
""" |
|
|
|
|
|
|
|
from IPython.display import display, Image |
|
|
|
import subprocess |
|
import seaborn as sns |
|
import matplotlib.pyplot as plt |
|
|
|
subprocess.run(["pip", "install", "datasets", "geopandas", "seaborn", "matplotlib", "mplcursors", "pandas"]) |
|
|
|
|
|
from datasets import load_dataset |
|
import seaborn as sns |
|
import matplotlib.pyplot as plt |
|
import mplcursors |
|
import pandas as pd |
|
import geopandas as gpd |
|
|
|
|
|
dataset = load_dataset("Ziyuan111/DurhamTrees") |
|
|
|
|
|
df = pd.DataFrame(dataset['train']) |
|
|
|
|
|
def plot_interactive_scatter(): |
|
scatter = sns.scatterplot(data=df, x='X', y='Y', hue='species') |
|
plt.xlabel('X') |
|
plt.ylabel('Y') |
|
plt.legend([],[], frameon=False) |
|
cursor = mplcursors.cursor(hover=True) |
|
|
|
@cursor.connect("add") |
|
def on_add(sel): |
|
sel.annotation.set_text(df.iloc[sel.target.index]['species']) |
|
plt.savefig('interactive_scatter.png') |
|
plt.show() |
|
display(Image('interactive_scatter.png')) |
|
|
|
|
|
def plot_tree_sites(): |
|
gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.X, df.Y)) |
|
durham_center = {'x': -78.898619, 'y': 35.994033} |
|
fig, ax = plt.subplots(figsize=(10, 10)) |
|
gdf.plot(ax=ax, color='green') |
|
buffer = 0.05 |
|
ax.set_xlim([durham_center['x'] - buffer, durham_center['x'] + buffer]) |
|
ax.set_ylim([durham_center['y'] - buffer, durham_center['y'] + buffer]) |
|
ax.set_title('Tree Planting Sites in Durham') |
|
ax.set_xlabel('Longitude') |
|
ax.set_ylabel('Latitude') |
|
ax.set_axis_off() |
|
plt.savefig('tree_sites.png') |
|
plt.show() |
|
display(Image('tree_sites.png')) |
|
|
|
|
|
def print_correlation_matrix(): |
|
correlation_matrix = df[['vocs', 'coremoved_ozperyr', 'coremoved_dolperyr']].corr() |
|
print(correlation_matrix) |
|
|
|
|
|
plot_interactive_scatter() |
|
plot_tree_sites() |
|
print_correlation_matrix() |
|
|
|
|
|
|
|
plt.show() |