Skip to content

Commit

Permalink
enhanced code of scatterPlot(refer issue sustainability-lab#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanvi-Jain01 committed Jun 30, 2023
1 parent ef99aef commit 03f403a
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions vayu/scatterPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,28 @@ def scatterPlot(df, x, y, **kwargs):
import matplotlib.cm as cm
from math import pi

pm10 = df.pm10
o3 = df.o3
ws = df.ws
wd = df.wd
nox = df.nox
no2 = df.no2


#########################################
# converts wind data to randians
df = pd.DataFrame({"speed": ws, "direction": wd})
df["speed_x"] = df["speed"] * np.sin(df["direction"] * pi / 180.0)
df["speed_y"] = df["speed"] * np.cos(df["direction"] * pi / 180.0)
#df1 = pd.DataFrame({"speed": ws, "direction": wd})
df["speed"+str(x)] = df['ws'] * np.sin(df['wd'] * pi / 180.0)
df["speed"+str(y)] = df['ws'] * np.cos(df['wd'] * pi / 180.0)
fig, ax = plt.subplots(figsize=(8, 8), dpi=80)
x0, x1 = ax.get_xlim()
y0, y1 = ax.get_ylim()
ax.set_aspect("equal")
_ = df.plot(kind="scatter", x="speed_x", y="speed_y", alpha=0.35, ax=ax)
#ax.set_aspect("equal")
_ = df.plot(kind="scatter", x="speed"+str(x), y="speed"+str(y), alpha=0.35, ax=ax)
plt.show()


####################################
# simple seaborn plot that shows how given variables relate with one another
if x == "nox":
x = nox
elif x == "no2":
x = no2
elif x == "o3":
x = o3
elif x == "pm10":
x = pm10
if y == "nox":
y = nox
elif y == "no2":
y = no2
elif y == "o3":
y = o3
elif y == "pm10":
y = pm10

sns.jointplot(x=x, y=y, kind="hex")

sns.jointplot(x=df[x].values, y=df[y].values, kind="hex")
plt.xlabel(x)
plt.ylabel(y)
plt.show()


# =============================================================================
# df = pd.read_csv("mydata.csv")
# scatterPlot(df,'nox','no2')
Expand Down

0 comments on commit 03f403a

Please sign in to comment.