Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions ESMBenchmarkViz/core_portrait_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
LinearColorMapper,
OpenURL,
Patches,
Span,
TapTool,
)
from bokeh.plotting import figure, show
Expand All @@ -35,6 +36,7 @@ def portrait_plot(
yaxis_labels: List[str],
width: Union[int, str] = 600,
height: Union[int, str] = 600,
glyph_rows: Optional[int] = None,
static: bool = False,
static_filename: str = "./static_portrait_plot.png",
annotate: bool = False,
Expand Down Expand Up @@ -177,8 +179,11 @@ def portrait_plot(
if num_divide != len(annotate_data):
sys.exit("Error: annotate_data.shape[0] is not equal to num_divide")

xpts_list, ypts_list = get_x_y_points(num_divide)
positions = get_positions(num_divide)
if glyph_rows:
xpts_list, ypts_list, positions = get_glyph_row_points(glyph_rows)
else:
xpts_list, ypts_list = get_x_y_points(num_divide)
positions = get_positions(num_divide)

# Prepare data for plotting
# ~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -450,6 +455,15 @@ def portrait_plot(
)
plot.add_layout(color_bar, cbar_place)

# if using glyph rows, add borders
if glyph_rows:
line_locations = np.arange(0, len(yaxis_labels) + 1, 1)
for loc in line_locations:
h_lines = Span(
location=loc, dimension="width", line_color="black", line_width=2
)
plot.add_layout(h_lines)

# Link to open when clicked
if clickable:
taptool = plot.select(type=TapTool)
Expand Down Expand Up @@ -774,3 +788,22 @@ def get_positions(num_sectors: int):
positions = ["box"]

return positions


def get_glyph_row_points(glyph_rows: int):

xpts = [0, 0, 1, 1]
xpts_list = [xpts] * glyph_rows
row_height = 1 / glyph_rows
ypts_list = []
positions = []
for g in range(0, glyph_rows):
gypts = np.arange(0, 1 + row_height, row_height).astype("float")
gypts = np.round(gypts, 3)
gypts_list = [float(x) for x in gypts]
g_array = [gypts_list[g], gypts_list[g + 1], gypts_list[g + 1], gypts_list[g]]
ypts_list.append(g_array)
position = f"region{g + 1}"
positions.append(position)

return xpts_list, ypts_list, positions
Loading
Loading