@@ -86,53 +86,46 @@ def _to_cmaps(cmap: Optional[Union[str, List[str]]]) -> List[str]:
8686 return [DEFAULT_CMAP ]
8787 if isinstance (cmap , str ):
8888 return [cmap ]
89- elif isinstance (cmap , list ):
89+ if isinstance (cmap , list ):
9090 return cmap
91- else :
92- raise ValueError (f"Invalid cmap type: { type (cmap )} . Expected str or list[str]." )
91+ raise ValueError (f"Invalid cmap type: { type (cmap )} . Expected str or list[str]." )
9392
9493
9594def _to_colors (colors : Union [np .ndarray , List [float ]]) -> np .ndarray :
9695 """Convert colors to a numpy array."""
9796 colors_arr = np .array (colors )
9897 if colors_arr .ndim == 1 :
9998 return colors_arr .reshape (- 1 , 1 )
100- elif colors_arr .ndim == 2 :
99+ if colors_arr .ndim == 2 :
101100 return colors_arr
102- else :
103- raise ValueError (
104- f"Invalid colors shape: { colors_arr .shape } . Expected 1D or 2D array."
105- )
101+ raise ValueError (
102+ f"Invalid colors shape: { colors_arr .shape } . Expected 1D or 2D array."
103+ )
106104
107105
108106def _to_titles (title : Optional [Union [str , List [str ]]], colors_num : int ) -> List [str ]:
109107 if title is None :
110108 return [f"{ i } " for i in range (colors_num )]
111- elif isinstance (title , str ):
109+ if isinstance (title , str ):
112110 if colors_num == 1 :
113111 return [title ]
114- else :
115- return [f"{ title } [{ i } ]" for i in range (colors_num )]
116- elif isinstance (title , list ) and len (title ) == colors_num :
112+ return [f"{ title } [{ i } ]" for i in range (colors_num )]
113+ if isinstance (title , list ) and len (title ) == colors_num :
117114 return title
118- else :
119- raise ValueError (
120- f"Invalid title type: { type (title )} . Expected str or list[str]."
121- )
115+ raise ValueError (f"Invalid title type: { type (title )} . Expected str or list[str]." )
122116
123117
124118def _to_node_sizes (
125119 node_size : Optional [Union [int , float , List [Union [int , float ]]]],
126120) -> List [float ]:
127121 if isinstance (node_size , (int , float )):
128122 return [node_size ]
129- elif isinstance (node_size , list ):
123+ if isinstance (node_size , list ):
130124 return node_size
131- else :
132- raise ValueError (
133- f"Invalid node_size type: { type (node_size )} . "
134- "Expected int, float or list[int, float]."
135- )
125+ raise ValueError (
126+ f"Invalid node_size type: { type (node_size )} . "
127+ "Expected int, float or list[int, float]."
128+ )
136129
137130
138131def _get_cmap_rgb (cmap : str ):
@@ -152,6 +145,19 @@ def plot_plotly(
152145 width : Optional [int ] = None ,
153146 height : Optional [int ] = None ,
154147) -> go .Figure :
148+ """
149+ Plot a Mapper graph using Plotly.
150+
151+ :param mapper_plot: The Mapper plot object containing the graph and positions.
152+ :param colors: Colors for the nodes, can be a 1D or 2D numpy array or a list.
153+ :param node_size: Size of the nodes, can be a single value or a list of values.
154+ :param title: Title for the color bar, can be a string or a list of strings.
155+ :param agg: Aggregation function to apply to the colors, defaults to np.nanmean.
156+ :param cmap: Colormap to use for the nodes, can be a string or a list of strings.
157+ :param width: Width of the plot, defaults to None (auto).
158+ :param height: Height of the plot, defaults to None (auto).
159+ :return: A Plotly Figure object containing the Mapper graph.
160+ """
155161 cmaps = _to_cmaps (cmap )
156162 colors = _to_colors (colors )
157163 colors_num = colors .shape [1 ]
0 commit comments