-
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
Minor Issue: Incorrect subplot syntax in timePlot function #40
Comments
Suggestions:
|
@patel-zeel I have implemented visualization using Changes:I have modified the method signature, I am removing the From: def timePlot(df, year, month, pollutants=["ws", "nox", "o3", "pm25", "pm10"]): To: def timePlot(df, year, pollutants=["ws", "nox", "o3", "pm25", "pm10"]): Improved Code:import plotly.graph_objects as go
def timePlot(df, year, month, pollutants=["ws", "nox", "o3", "pm25", "pm10"]):
# Cuts the df down to the month specified
df.index = pd.to_datetime(df.date)
df_n_1 = df[(df.index.month == int(month)) & (df.index.year == int(year))]
fig = go.Figure()
for pollutant in pollutants:
values = df_n_1[pollutant]
# Add trace for each pollutant
fig.add_trace(go.Scatter(
x=values.index,
y=values.values,
name=pollutant
))
# Configure layout
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=1, label="1d", step="day", stepmode="backward"),
dict(count=7, label="1w", step="day", stepmode="backward"),
dict(count=1, label="1m", step="month", stepmode="backward"),
dict(count=6, label="6m", step="month", stepmode="backward"),
dict(count=1, label="YTD", step="year", stepmode="backward"),
dict(count=1, label="1y", step="year", stepmode="backward"),
dict(step="all")
])
),
rangeslider=dict(
visible=True
),
type="date"
)
)
fig.show()
timePlot(df, 2022, 8, pollutants=['pm25', 'pm10', 'no', 'no2', 'nox', 'nh3', 'so2', 'co', 'o3', 'benzene', 'toluene']) Output: |
This was referenced Jul 10, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
timePlot: ValueError in subplot function
While I was exploring this library, I tried
timePlot
where my dataframe, pollutants and datatype was correct, but I was still facing the error of plots for my pollutants.Code:
Error:
Issue-1:
Source Code:
vayu/vayu/timePlot.py
Line 46 in ef99aef
Explaination:
The above code line prevents the proper execution of the code.
The plt.subplot() function expects the subplot number to be specified as three separate integers: the number of rows, the number of columns, and the index of the current subplot.
Solution:
The above code line will make the execution correct.
Issue-2:
I copied the source code of
timePlot
fromvayu
and I was trying to create a solution where I again got an error which is explained below.Code:
Error:
Explaination:
The
zip()
function in Python expects multiple iterables as its arguments. In the code I provided above, when plt.subplots() returns a singleaxs
object (when there is only one subplot), the axs variable becomes that single Axes object. It treats thataxs
object as an iterable of individual items, resulting in the TypeError that I encountered.Solution:
By converting
axs
into alist
usingnp.atleast_1d()
, you ensure thataxs
is always treated as alist
, regardless of whether it contains a single Axes object or multiple Axes objects. This allows thefor loop
to correctly iterate over the elements ofaxs
, whether it's a single Axes object or a list of Axes objects, which will resolve theType error
.Below example solves the above 2 issues
Example:
Output:
The text was updated successfully, but these errors were encountered: