@@ -9,6 +9,17 @@ and TV shows. Palettes are exposed as plotnine scales:
99
1010This article mirrors the original R package vignette using plotnine.
1111
12+ ``` python
13+ import numpy as np
14+ import pandas as pd
15+ from plotnine import *
16+ from plotnine.data import diamonds, mtcars
17+
18+ from ggsci import *
19+
20+ LAST = None
21+ ```
22+
1223``` python exec="on" session="default"
1324# Imports shared by all chunks in this article
1425import base64
@@ -39,7 +50,6 @@ from plotnine import (
3950 theme_dark,
4051 theme_void,
4152)
42- from plotnine.composition import plot_spacer
4353from plotnine.data import diamonds, mtcars
4454from plotnine.options import set_option
4555
@@ -68,40 +78,6 @@ def render_png(
6878
6979# A shared handle for the last-computed plot/composition
7080LAST = None
71-
72-
73- # Placeholder panel to pad compositions to equal column counts
74- def blank_panel ():
75- # Build a grid matching p4's tile layout, but with white tiles (no fill mapping)
76- try :
77- df = x_melt[[" Var1" , " Var2" ]].copy()
78- except NameError :
79- # Fallback to a 6x6 grid if x_melt is not yet defined
80- k = 6
81- df = pd.DataFrame(
82- [(i, j) for i in range (k) for j in range (k)], columns = [" Var1" , " Var2" ]
83- )
84- return (
85- ggplot(df, aes(" Var1" , " Var2" ))
86- + geom_tile(fill = " white" , color = " black" , size = 0.3 )
87- + scale_x_continuous(expand = (0 , 0 ))
88- + scale_y_continuous(expand = (0 , 0 ))
89- + theme_bw()
90- + theme(
91- legend_position = " none" ,
92- plot_background = element_rect(fill = " white" ),
93- panel_background = element_rect(fill = " white" ),
94- axis_title_x = element_blank(),
95- axis_title_y = element_blank(),
96- axis_text_x = element_blank(),
97- axis_text_y = element_blank(),
98- axis_ticks = element_blank(),
99- axis_line = element_blank(),
100- panel_border = element_blank(),
101- panel_grid_major = element_blank(),
102- panel_grid_minor = element_blank(),
103- )
104- )
10581```
10682
10783## Discrete color palettes
@@ -406,6 +382,39 @@ p4 = (
406382 panel_grid_minor = element_blank(),
407383 )
408384)
385+
386+ # Placeholder panel to pad compositions to equal column counts
387+ def blank_panel ():
388+ # Build a grid matching p4's tile layout, but with white tiles (no fill mapping)
389+ try :
390+ df = x_melt[[" Var1" , " Var2" ]].copy()
391+ except NameError :
392+ # Fallback to a 6x6 grid if x_melt is not yet defined
393+ k = 6
394+ df = pd.DataFrame(
395+ [(i, j) for i in range (k) for j in range (k)], columns = [" Var1" , " Var2" ]
396+ )
397+ return (
398+ ggplot(df, aes(" Var1" , " Var2" ))
399+ + geom_tile(fill = " white" , color = " black" , size = 0.3 )
400+ + scale_x_continuous(expand = (0 , 0 ))
401+ + scale_y_continuous(expand = (0 , 0 ))
402+ + theme_bw()
403+ + theme(
404+ legend_position = " none" ,
405+ plot_background = element_rect(fill = " white" ),
406+ panel_background = element_rect(fill = " white" ),
407+ axis_title_x = element_blank(),
408+ axis_title_y = element_blank(),
409+ axis_text_x = element_blank(),
410+ axis_text_y = element_blank(),
411+ axis_ticks = element_blank(),
412+ axis_line = element_blank(),
413+ panel_border = element_blank(),
414+ panel_grid_major = element_blank(),
415+ panel_grid_minor = element_blank(),
416+ )
417+ )
409418```
410419
411420### GSEA (diverging)
0 commit comments