Skip to content

Commit

Permalink
Add LineChart class
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Dec 22, 2023
1 parent ae45627 commit 325e8e5
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions geemap/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,39 @@ def plot_chart(self):
plt.show()


class LineChart(BarChart):
"""A class to define variables and get_data method for a line chart."""

def __init__(self, features, labels, name="line.chart", **kwargs):
super().__init__(features, labels, name, **kwargs)

def plot_chart(self):
fig = plt.figure(
title=self.title,
legend_location=self.legend_location,
)

self.line_chart = plt.plot(
self.x_data,
self.y_data,
label=self.labels,
)

self.generate_tooltip()
plt.ylim(*self.get_ylim())
if self.xlabel:
plt.xlabel(self.xlabel)
if self.ylabel:
plt.ylabel(self.ylabel)

if self.width:
fig.layout.width = self.width
if self.height:
fig.layout.height = self.height

plt.show()


class Feature_ByFeature(BarChart):
"""A object to define variables and get_data method."""

Expand Down Expand Up @@ -217,6 +250,42 @@ def get_data(self, xProperty, new_column_names):
return x_data, y_data


class Image_byClass(LineChart):
"""A object to define variables and get_data method."""

def __init__(
self,
image,
region,
reducer,
scale,
classLabels,
xLabels,
xProperty,
name="image.byClass",
**kwargs,
):
self.classLabels = classLabels
self.xLabels = xLabels
super().__init__(image, classLabels, name, **kwargs)
self.x_data, self.y_data = self.get_data(
image, region, xProperty, reducer, scale
)

def get_data(self, image, region, xProperty, reducer, scale):
fc = zonal_stats(
image, region, stat_type=reducer, scale=scale, verbose=False, return_fc=True
)
bands = image.bandNames().getInfo()
df = ee_to_df(fc)[bands + [xProperty]]
columns = df.columns.tolist()
columns.remove(xProperty)
x_data = columns
y_data = df.drop([xProperty], axis=1).to_numpy()

return x_data, y_data


def feature_byFeature(
features: ee.FeatureCollection, xProperty: str, yProperties: list, **kwargs
):
Expand Down

0 comments on commit 325e8e5

Please sign in to comment.