-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhanced code of scatterPlot (refer issue #43) #46
base: master
Are you sure you want to change the base?
Conversation
I think currently, the function is confusing. I am thinking of following changes for this function. Changes suggested:
New function may look like: import pandas as pd
from typing import Optional
def scatter_plot(df: pd.DataFrame, x: str, y: str, hue: Optional[str] = None):
return sns.jointplot(data=df, x=x, y=y, hue=hue) |
@patel-zeel SAMPLE CODE: import numpy as np
import pandas as pd
np.random.seed(42)
start_date = pd.to_datetime('2022-01-01')
end_date = pd.to_datetime('2022-12-31')
dates = pd.date_range(start_date, end_date)
pm25_values = np.random.rand(365) # Generate 365 random values
o3_values = np.random.rand(365)
ws_values = np.random.rand(365)
wd_values = np.random.rand(365)
pm10_values = np.random.rand(365)
df1 = pd.DataFrame({
'date': dates,
'pm25': pm25_values,
'o3':o3_values,
'ws': ws_values,
'wd': wd_values,
'pm10': pm10_values
})
df1['date'] = df1['date'].dt.strftime('%Y-%m-%d') # Convert date format to 'YYYY-MM-DD'
print(df1) IMPROVED CODE: import seaborn as sns
import matplotlib.pyplot as plt
from math import pi
def scatter_plot(df:pd.DataFrame, x:str, y:str, **kwargs):
sns.jointplot(x=df[x].values, y=df[y].values, kind="hex")
#print(x,y)
plt.xlabel(x)
plt.ylabel(y)
plt.savefig("scatterPlot.png", bbox_inches="tight",dpi=300)
print("Your plots has also been saved")
plt.show()
scatter_plot(df1, 'pm10', 'pm25') OUTPUT: |
@Tanvi-Jain01 xlabel, ylabel are automatically added by |
@Tanvi-Jain01 I have added the quarto template in the master branch. So, please add a notebook showing the usage of |
######################################### | ||
# 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() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this part of code.
plt.xlabel(x) | ||
plt.ylabel(y) | ||
plt.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are also not needed and can be removed.
This PR solves #43.
Before
vayu/vayu/scatterPlot.py
Lines 22 to 27 in ef99aef
vayu/vayu/scatterPlot.py
Lines 42 to 57 in ef99aef
After
Usage
Plots