Skip to content

Commit 8065f4b

Browse files
Merge pull request #34 from PCMDI/33_kristinchang3_glyphRows
Adding glyph_row parameter
2 parents d141261 + 8a1eca0 commit 8065f4b

File tree

2 files changed

+283
-26
lines changed

2 files changed

+283
-26
lines changed

ESMBenchmarkViz/core_portrait_plot.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
LinearColorMapper,
2121
OpenURL,
2222
Patches,
23+
Span,
2324
TapTool,
2425
)
2526
from bokeh.plotting import figure, show
@@ -35,6 +36,7 @@ def portrait_plot(
3536
yaxis_labels: List[str],
3637
width: Union[int, str] = 600,
3738
height: Union[int, str] = 600,
39+
glyph_rows: Optional[int] = None,
3840
static: bool = False,
3941
static_filename: str = "./static_portrait_plot.png",
4042
annotate: bool = False,
@@ -177,8 +179,11 @@ def portrait_plot(
177179
if num_divide != len(annotate_data):
178180
sys.exit("Error: annotate_data.shape[0] is not equal to num_divide")
179181

180-
xpts_list, ypts_list = get_x_y_points(num_divide)
181-
positions = get_positions(num_divide)
182+
if glyph_rows:
183+
xpts_list, ypts_list, positions = get_glyph_row_points(glyph_rows)
184+
else:
185+
xpts_list, ypts_list = get_x_y_points(num_divide)
186+
positions = get_positions(num_divide)
182187

183188
# Prepare data for plotting
184189
# ~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -450,6 +455,15 @@ def portrait_plot(
450455
)
451456
plot.add_layout(color_bar, cbar_place)
452457

458+
# if using glyph rows, add borders
459+
if glyph_rows:
460+
line_locations = np.arange(0, len(yaxis_labels) + 1, 1)
461+
for loc in line_locations:
462+
h_lines = Span(
463+
location=loc, dimension="width", line_color="black", line_width=2
464+
)
465+
plot.add_layout(h_lines)
466+
453467
# Link to open when clicked
454468
if clickable:
455469
taptool = plot.select(type=TapTool)
@@ -774,3 +788,22 @@ def get_positions(num_sectors: int):
774788
positions = ["box"]
775789

776790
return positions
791+
792+
793+
def get_glyph_row_points(glyph_rows: int):
794+
795+
xpts = [0, 0, 1, 1]
796+
xpts_list = [xpts] * glyph_rows
797+
row_height = 1 / glyph_rows
798+
ypts_list = []
799+
positions = []
800+
for g in range(0, glyph_rows):
801+
gypts = np.arange(0, 1 + row_height, row_height).astype("float")
802+
gypts = np.round(gypts, 3)
803+
gypts_list = [float(x) for x in gypts]
804+
g_array = [gypts_list[g], gypts_list[g + 1], gypts_list[g + 1], gypts_list[g]]
805+
ypts_list.append(g_array)
806+
position = f"region{g + 1}"
807+
positions.append(position)
808+
809+
return xpts_list, ypts_list, positions

0 commit comments

Comments
 (0)