Skip to content

[dist_12x24 and plot_12x24_contours] enhancement to report values for periods between Dec-Jan and 23-0 hour #618

Description

@BiancaMorandi

Is your feature request related to a problem? Please describe.
Plot generated using dist_12x24 and plot_12x24_contours functions could be improved by showing what happens between 23 and 0, and Dec and Jan, and Ideally having wraparound/continuity across in the contours across those thresholds. The issue comes from the fact that data points are averaged within a given bin, but then plotted 'on' the tick mark at the start of each month/hour etc. Between these ticks, the tool is then interpolating the contours. This can distort the picture slightly for the reader: 1) user might think the plot isn't telling us what happens between 23:00 and 00:00 or between Dec and Jan (as that area isn't shown on the plot). Also 2) The contours should wrap around/match with the other side of the plot with continuity, as the boundaries are kind of arbitrary.

Describe the solution you'd like
Plot should offset the binned values to between the ticks, append the wrap around values on all sides of the dataframe, plot and then clip the axes to include an extra 0.5 units in all directions.

See below plot generated by function and plot generated with proposed fix. Both plots can be generated with code below.

Current plot

Image

Proposed plot with code fix

Image

Example code

import brightwind as bw
import matplotlib.pyplot as plt
import numpy as np
import calendar
COLOR_PALETTE = bw.analyse.plot.COLOR_PALETTE

# original call function
data = bw.load_csv(bw.demo_datasets.demo_data)
plt, stats = bw.dist_12x24(data["Spd80mN"], return_data=True)
plt

# proposed fix on plot_12x24_contours
## Step 1: Duplicate first and last columns
import pandas as pd
first_col = stats.iloc[:, 0]   # Month 1
last_col = stats.iloc[:, -1]   # Month 12
df_with_cols = pd.concat([last_col, stats, first_col], axis=1)
## Rename to avoid duplicate column name confusion (optional)
df_with_cols.columns = [0] + list(stats.columns) + [13]

## Step 2: Duplicate first and last rows
first_row = df_with_cols.iloc[[0]]   # Hour 0
last_row = df_with_cols.iloc[[-1]]   # Hour 23
df_final = pd.concat([last_row, df_with_cols, first_row], ignore_index=False)

## Rename index to avoid duplicate index confusion (optional)
df_final.index = [-1] + list(stats.index) + [24]

df_final

## fix of plot_12x24_contours function
fig, ax = plt.subplots(figsize=(15, 10))
x = ax.contourf(df_final.columns, df_final.index, df_final.values, cmap=COLOR_PALETTE.color_map)
cbar = fig.colorbar(x)
cbar.ax.set_ylabel(label[1].capitalize() + " of " + label[0])
ax.set_xlabel('Month of Year')
ax.set_ylabel('Hour of Day')
month_names = calendar.month_abbr[1:13]
ax.set_xticks(df_final.columns[1:13] - 0.5)
ax.set_xticklabels([month_names[i - 1] for i in df_final.columns[1:13]])
ax.set_yticks(np.arange(-0.5, 23, 1))
ax.set_yticklabels([f"{i}" for i in range(24)])
ax.set_ylim(-0.5, 23.5)
ax.set_xlim(0.5, 12.5)
ax.get_figure()

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions