99__all__ = ['halfviolin' , 'get_swarm_spans' , 'error_bar' , 'check_data_matches_labels' , 'normalize_dict' , 'width_determine' ,
1010 'single_sankey' , 'sankeydiag' , 'summary_bars_plotter' , 'contrast_bars_plotter' , 'swarm_bars_plotter' ,
1111 'delta_text_plotter' , 'DeltaDotsPlotter' , 'slopegraph_plotter' , 'plot_minimeta_or_deltadelta_violins' ,
12- 'effect_size_curve_plotter' , 'grid_key_WIP ' , 'barplotter' , 'table_for_horizontal_plots' , 'swarmplot' ,
12+ 'effect_size_curve_plotter' , 'gridkey_plotter ' , 'barplotter' , 'table_for_horizontal_plots' , 'swarmplot' ,
1313 'SwarmPlot' ]
1414
1515# %% ../nbs/API/plot_tools.ipynb 4
@@ -1609,9 +1609,10 @@ def effect_size_curve_plotter(ticks_to_plot, results, ci_type, contrast_axes, vi
16091609 return current_group , current_control , current_effsize , contrast_xtick_labels
16101610
16111611
1612- def grid_key_WIP (is_paired , idx , all_plot_groups , gridkey_rows , rawdata_axes , contrast_axes ,
1613- plot_data , xvar , yvar , results , show_delta2 , show_mini_meta , float_contrast ,
1614- plot_kwargs , x1_level , experiment_label ):
1612+ def gridkey_plotter (is_paired , idx , all_plot_groups , gridkey_rows , rawdata_axes , contrast_axes ,
1613+ plot_data , xvar , yvar , results , show_delta2 , show_mini_meta ,
1614+ plot_kwargs , x1_level , experiment_label , float_contrast , horizontal ,
1615+ delta_delta , mini_meta_delta , effect_size ):
16151616
16161617 gridkey_delimiters = plot_kwargs ["gridkey_delimiters" ] # Auto parser for gridkey - implemented by SangyuXu
16171618 if gridkey_rows == "auto" :
@@ -1697,7 +1698,7 @@ def grid_key_WIP(is_paired, idx, all_plot_groups, gridkey_rows, rawdata_axes, co
16971698 table_cellcols .append (list_of_Ns )
16981699
16991700 # Adds a row for effectsizes with effectsize values
1700- if gridkey_show_es :
1701+ if gridkey_show_es and not horizontal :
17011702 gridkey_rows .append ("\u0394 " )
17021703 effsize_list = []
17031704 results_list = results .test .to_list ()
@@ -1721,40 +1722,102 @@ def grid_key_WIP(is_paired, idx, all_plot_groups, gridkey_rows, rawdata_axes, co
17211722
17221723 table_cellcols .append (effsize_list )
17231724
1724- # If Gardner-Altman plot, plot on raw data and not contrast axes
1725- if float_contrast :
1726- axes_ploton = rawdata_axes
1725+ # Set the axes to plot on
1726+ if float_contrast or horizontal :
1727+ ax_to_plot = rawdata_axes
17271728 else :
1728- axes_ploton = contrast_axes
1729-
1730- # Account for extended x axis in case of show_delta2 or show_mini_meta
1731- x_groups_for_width = len (groups_for_gridkey )
1732- if show_delta2 or show_mini_meta :
1733- x_groups_for_width += 2
1734- gridkey_width = len (groups_for_gridkey ) / x_groups_for_width
1735-
1736- gridkey = axes_ploton .table (
1737- cellText = table_cellcols ,
1738- rowLabels = gridkey_rows ,
1739- cellLoc = "center" ,
1740- bbox = [
1741- 0 ,
1742- - len (gridkey_rows ) * 0.1 - 0.05 ,
1743- gridkey_width ,
1744- len (gridkey_rows ) * 0.1 ,
1745- ],
1746- ** {"alpha" : 0.5 }
1747- )
1729+ ax_to_plot = contrast_axes
1730+
1731+ # Add delta-delta or mini_meta details to the table
1732+ if show_mini_meta or show_delta2 :
1733+ if show_delta2 :
1734+ added_group_name = ["deltas' g" ] if effect_size == "delta_g" else ["delta-delta" ]
1735+ else :
1736+ added_group_name = ["Weighted delta" ]
1737+ gridkey_rows = added_group_name + gridkey_rows
1738+ table_cellcols = [["" ]* len (table_cellcols [0 ])] + table_cellcols
1739+
1740+ for group_idx , group_vals in enumerate (table_cellcols ):
1741+ if group_idx == 0 :
1742+ added_group = ['' , "\u25CF " ]
1743+ elif gridkey_show_es and (group_idx == len (table_cellcols )- 1 ) and not horizontal :
1744+ added_delta_effectsize = delta_delta .difference if show_delta2 else mini_meta_delta .difference
1745+ added_delta_effectsize_str = np .format_float_positional (
1746+ added_delta_effectsize ,
1747+ precision = 2 ,
1748+ sign = True ,
1749+ trim = "k" ,
1750+ min_digits = 2 ,
1751+ )
1752+ added_group = ['-' , added_delta_effectsize_str ]
1753+ else :
1754+ added_group = ['' , '' ]
1755+ for n in added_group :
1756+ group_vals .append (n )
17481757
1749- # modifies row label cells
1750- for cell in gridkey ._cells :
1751- if cell [1 ] == - 1 :
1752- gridkey ._cells [cell ].visible_edges = "open"
1753- gridkey ._cells [cell ].set_text_props (** {"ha" : "right" })
1758+ # Create the table object
1759+ if horizontal :
1760+ # Convert the cells format for horizontal table plotting
1761+ converted_list = []
1762+ for j in range (0 , len (table_cellcols [0 ])):
1763+ temp_list = []
1764+ for i in table_cellcols :
1765+ temp_list .append (i [j ])
1766+ converted_list .append (temp_list )
1767+
1768+ # Plot the table for horizontal format
1769+ gridkey = ax_to_plot .table (
1770+ cellText = converted_list ,
1771+ cellLoc = "center" ,
1772+ bbox = [
1773+ - len (gridkey_rows ) * 0.2 ,
1774+ 0 ,
1775+ len (gridkey_rows ) * 0.2 ,
1776+ 1
1777+ ],
1778+ ** {"alpha" : 0.5 , "zorder" : 5 }
1779+ )
1780+
1781+ # Add the column labels as text below the table
1782+ text_locs = np .arange ((- len (gridkey_rows )* 0.2 ) + 0.1 , 0 , 0.2 )
1783+ for loc , txt in zip (text_locs , gridkey_rows ):
1784+ ax_to_plot .text (
1785+ loc + 0.04 ,
1786+ - 0.01 ,
1787+ txt ,
1788+ transform = ax_to_plot .transAxes ,
1789+ fontsize = 10 ,
1790+ ha = 'right' ,
1791+ rotation = 45 ,
1792+ va = 'top'
1793+ )
1794+ else :
1795+ # Plot the table for vertical format
1796+ gridkey = ax_to_plot .table (
1797+ cellText = table_cellcols ,
1798+ rowLabels = gridkey_rows ,
1799+ cellLoc = "center" ,
1800+ bbox = [
1801+ 0 ,
1802+ - len (gridkey_rows ) * 0.1 - 0.05 ,
1803+ 1 ,
1804+ len (gridkey_rows ) * 0.1 ,
1805+ ],
1806+ ** {"alpha" : 0.5 }
1807+ )
1808+ # modifies row label cells
1809+ for cell in gridkey ._cells :
1810+ if cell [1 ] == - 1 :
1811+ gridkey ._cells [cell ].visible_edges = "open"
1812+ gridkey ._cells [cell ].set_text_props (** {"ha" : "right" })
17541813
17551814 # turns off both x axes
1756- rawdata_axes .get_xaxis ().set_visible (False )
1757- contrast_axes .get_xaxis ().set_visible (False )
1815+ if horizontal :
1816+ rawdata_axes .get_yaxis ().set_visible (False )
1817+ contrast_axes .get_yaxis ().set_visible (False )
1818+ else :
1819+ rawdata_axes .get_xaxis ().set_visible (False )
1820+ contrast_axes .get_xaxis ().set_visible (False )
17581821
17591822def barplotter (xvar , yvar , all_plot_groups , rawdata_axes , plot_data , bar_color , plot_palette_bar ,
17601823 plot_kwargs , barplot_kwargs , horizontal ):
0 commit comments