Skip to content

Commit

Permalink
Change from matplotlib to bqplot
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Apr 21, 2024
1 parent 3869f93 commit 972c09a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
11 changes: 11 additions & 0 deletions hypercoast/hypercoast.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,14 @@ def spectral_to_df(self, **kwargs):

df = pd.DataFrame(self._spectral_data, **kwargs)
return df

def spectral_to_csv(self, filename, index=True, **kwargs):
"""Saves the spectral data to a CSV file.
Args:
filename (str): The output CSV file.
index (bool, optional): Whether to write the index. Defaults to True.
"""
df = self.spectral_to_df()
df = df.rename_axis("band")
df.to_csv(filename, index=index, **kwargs)
20 changes: 15 additions & 5 deletions hypercoast/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import ipyleaflet
import ipywidgets as widgets
import matplotlib.pyplot as plt
import numpy as np
from bqplot import pyplot as plt
from IPython.core.display import display


Expand Down Expand Up @@ -87,12 +87,22 @@ def handle_interaction(**kwargs):
"wavelengths"
].values

self._host_map._spectral_data[f"({lat:.4f},{lon:.4f})"] = da.values
self._host_map._spectral_data[f"({lat:.4f} {lon:.4f})"] = da.values

da[da < 0] = np.nan
fig, ax = plt.subplots()
da.plot.line(ax=ax)
display(fig)
# fig, ax = plt.subplots()
# da.plot.line(ax=ax)
# display(fig)
fig_margin = {"top": 20, "bottom": 35, "left": 50, "right": 20}
fig = plt.figure(
# title=None,
fig_margin=fig_margin,
layout={"width": "500px", "height": "300px"},
)
plt.plot(da.coords[da.dims[0]].values, da.values)
plt.xlabel("Wavelength (nm)")
plt.ylabel("Reflectance")
plt.show()

self._host_map.default_style = {"cursor": "crosshair"}

Expand Down

0 comments on commit 972c09a

Please sign in to comment.