diff --git a/raster/r.profile/r.profile.html b/raster/r.profile/r.profile.html index a2e75eb0cc7..b5801a28055 100644 --- a/raster/r.profile/r.profile.html +++ b/raster/r.profile/r.profile.html @@ -219,6 +219,41 @@
+import grass.script as gs +import pandas as pd +import matplotlib.pyplot as plt + +# Run r.profile command +elevation = gs.read_command( + "r.profile", + input="elevation", + coordinates="641712,226095,641546,224138,641546,222048,641049,221186", + format="json", + flags="gc" +) + +# Load the JSON data into a dataframe +df = pd.read_json(elevation) + +# Convert the RGB color values to hex format for matplotlib +df["color"] = df.apply(lambda x: "#{:02x}{:02x}{:02x}".format(int(x["red"]), int(x["green"]), int(x["blue"])), axis=1) + +# Create the scatter plot +plt.figure(figsize=(10, 6)) +plt.scatter(df['distance'], df['elevation'], c=df['color'], marker='o') +plt.title('Profile of Distance vs. Elevation with Color Coding') +plt.xlabel('Distance (meters)') +plt.ylabel('Elevation') +plt.grid(True) +plt.show() +