py2ls 0.2.4__py3-none-any.whl → 0.2.4.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
py2ls/plot.py CHANGED
@@ -10,8 +10,8 @@ from cycler import cycler
10
10
  import logging
11
11
  import os
12
12
  import re
13
-
14
- from .ips import fsave, fload, mkdir, listdir, figsave, strcmp, unique, get_os, ssplit
13
+ from typing import Union
14
+ from .ips import fsave, fload, mkdir, listdir, figsave, strcmp, unique, get_os, ssplit,plt_font
15
15
  from .stats import *
16
16
  from .netfinder import get_soup, fetch
17
17
 
@@ -152,6 +152,36 @@ def heatmap(
152
152
  yticklabels=True, # Show row labels
153
153
  **kwargs,
154
154
  ):
155
+ """
156
+ plot heatmap or clustermap for a given dataset (DataFrame).
157
+
158
+ Parameters:
159
+ - data (pd.DataFrame): The input data to visualize.
160
+ - ax (matplotlib.Axes, optional): Axis object to plot on. If None and cluster=False, a new axis is created.
161
+ - kind (str, default="corr"): Type of heatmap to plot. Options:
162
+ - "corr": Correlation heatmap based on numeric columns.
163
+ - "direct": Direct visualization of the numeric data.
164
+ - "pivot": Creates a heatmap using the `pivot_table` method.
165
+ - columns (str or list, default="all"): Columns to include in the heatmap. For pivoting, this specifies the 'columns' argument.
166
+ - index (str, optional): For pivot heatmap, sets the 'index' argument.
167
+ - values (str, optional): For pivot heatmap, sets the 'values' argument.
168
+ - tri (str, default="u"): Specifies whether to show the 'upper' or 'lower' triangle in the heatmap.
169
+ - mask (bool, default=True): Whether to mask half of the correlation matrix.
170
+ - k (int, default=1): Controls how much of the triangle is masked in correlation heatmaps.
171
+ - annot (bool, default=True): If True, writes the data values in each cell.
172
+ - cmap (str, default="coolwarm"): The colormap for the heatmap.
173
+ - fmt (str, default=".2f"): String formatting code for annotating cells.
174
+ - cluster (bool, default=False): If True, a clustermap with hierarchical clustering is plotted.
175
+ - inplace (bool, default=False): If True, modifies the original data. Not currently used.
176
+ - figsize (tuple, default=(10, 8)): Size of the figure for the heatmap.
177
+ - row_cluster (bool, default=True): Perform clustering on rows.
178
+ - col_cluster (bool, default=True): Perform clustering on columns.
179
+ - dendrogram_ratio (tuple, default=(0.2, 0.1)): Adjust the size of the dendrograms.
180
+ - cbar_pos (tuple, default=(0.02, 1, 0.02, 0.1)): Adjust the position of the colorbar.
181
+ - xticklabels (bool, default=True): Show or hide the column labels.
182
+ - yticklabels (bool, default=True): Show or hide the row labels.
183
+ - **kwargs: Additional arguments passed to `sns.heatmap` or `sns.clustermap`.
184
+ """
155
185
  if ax is None and not cluster:
156
186
  ax = plt.gca()
157
187
  # Select numeric columns or specific subset of columns
@@ -162,7 +192,8 @@ def heatmap(
162
192
 
163
193
  kinds = ["corr", "direct", "pivot"]
164
194
  kind = strcmp(kind, kinds)[0]
165
- if kind == "corr":
195
+ print(kind)
196
+ if "corr" in kind: # correlation
166
197
  # Compute the correlation matrix
167
198
  data4heatmap = df_numeric.corr()
168
199
  # Generate mask for the upper triangle if mask is True
@@ -254,11 +285,26 @@ def heatmap(
254
285
  )
255
286
  # Return the Axes object for further customization if needed
256
287
  return ax
257
- elif kind == "direct":
288
+ elif "dir" in kind: # direct
258
289
  data4heatmap = df_numeric
259
- elif kind == "pivot":
260
- print('need 3 param: e.g., index="Task", columns="Model", values="Score"')
261
- data4heatmap = data.pivot(index=index, columns=columns, values=values)
290
+ elif "pi" in kind: # pivot
291
+ try:
292
+ print(
293
+ f'pivot: \n\tneed at least 3 param: e.g., index="Task", columns="Model", values="Score"'
294
+ )
295
+ data4heatmap = data.pivot(index=index, columns=columns, values=values)
296
+ except:
297
+ print(
298
+ f'pivot_table: \n\tneed at least 4 param: e.g., index="Task", columns="Model", values="Score",aggfunc="mean"'
299
+ )
300
+ aggfunc = "mean"
301
+ for k_, v_ in kwargs.items():
302
+ if "agg" in k_.lower():
303
+ aggfunc = v_
304
+ kwargs.pop(k_, None)
305
+ data4heatmap = data.pivot_table(
306
+ index=index, columns=columns, values=values, aggfunc=aggfunc
307
+ )
262
308
  else:
263
309
  print(f'"{kind}" is not supported')
264
310
  # Remove conflicting kwargs
@@ -1816,8 +1862,10 @@ def figsets(*args, **kwargs):
1816
1862
  matplotlib.rc("text", usetex=False)
1817
1863
 
1818
1864
  fig = plt.gcf()
1819
- fontsize = 11
1820
- fontname = "Arial"
1865
+ fontsize = kwargs.get("fontsize",11)
1866
+ plt.rcParams["font.size"]=fontsize
1867
+ fontname = kwargs.pop("fontname","Arial")
1868
+ fontname=plt_font(fontname) # 显示中文
1821
1869
  sns_themes = ["white", "whitegrid", "dark", "darkgrid", "ticks"]
1822
1870
  sns_contexts = ["notebook", "talk", "poster"] # now available "paper"
1823
1871
  scienceplots_styles = [
@@ -1843,6 +1891,7 @@ def figsets(*args, **kwargs):
1843
1891
  ]
1844
1892
 
1845
1893
  def set_step_1(ax, key, value):
1894
+ nonlocal fontsize, fontname
1846
1895
  if ("fo" in key) and (("size" in key) or ("sz" in key)):
1847
1896
  fontsize = value
1848
1897
  plt.rcParams.update({"font.size": fontsize})
@@ -1885,15 +1934,15 @@ def figsets(*args, **kwargs):
1885
1934
  if ("x" in key.lower()) and (
1886
1935
  "tic" not in key.lower() and "tk" not in key.lower()
1887
1936
  ):
1888
- ax.set_xlabel(value, fontname=fontname)
1937
+ ax.set_xlabel(value, fontname=fontname,fontsize=fontsize)
1889
1938
  if ("y" in key.lower()) and (
1890
1939
  "tic" not in key.lower() and "tk" not in key.lower()
1891
1940
  ):
1892
- ax.set_ylabel(value, fontname=fontname)
1941
+ ax.set_ylabel(value, fontname=fontname,fontsize=fontsize)
1893
1942
  if ("z" in key.lower()) and (
1894
1943
  "tic" not in key.lower() and "tk" not in key.lower()
1895
1944
  ):
1896
- ax.set_zlabel(value, fontname=fontname)
1945
+ ax.set_zlabel(value, fontname=fontname,fontsize=fontsize)
1897
1946
  if key == "xlabel" and isinstance(value, dict):
1898
1947
  ax.set_xlabel(**value)
1899
1948
  if key == "ylabel" and isinstance(value, dict):
@@ -2096,6 +2145,7 @@ def figsets(*args, **kwargs):
2096
2145
  plt.set_cmap(value)
2097
2146
 
2098
2147
  def set_step_2(ax, key, value):
2148
+ nonlocal fontsize, fontname
2099
2149
  if key == "figsize":
2100
2150
  pass
2101
2151
  if "xlim" in key.lower():
@@ -2135,9 +2185,9 @@ def figsets(*args, **kwargs):
2135
2185
  ax.grid(visible=False)
2136
2186
  if "tit" in key.lower():
2137
2187
  if "sup" in key.lower():
2138
- plt.suptitle(value)
2188
+ plt.suptitle(value,fontname=fontname,fontsize=fontsize)
2139
2189
  else:
2140
- ax.set_title(value)
2190
+ ax.set_title(value,fontname=fontname,fontsize=fontsize)
2141
2191
  if key.lower() in ["spine", "adjust", "ad", "sp", "spi", "adj", "spines"]:
2142
2192
  if isinstance(value, bool) or (value in ["go", "do", "ja", "yes"]):
2143
2193
  if value:
@@ -2873,13 +2923,26 @@ def plot_xy(
2873
2923
  x=None,
2874
2924
  y=None,
2875
2925
  ax=None,
2876
- kind: str = None, # Specify the kind of plot
2926
+ kind: Union[str, list] = None, # Specify the kind of plot
2927
+ verbose=False,
2928
+ **kwargs,
2929
+ ):
2930
+ # You can call the original plotxy function if needed
2931
+ # or simply replicate the functionality here
2932
+ return plotxy(data, x, y, ax, kind, verbose, **kwargs)
2933
+
2934
+
2935
+ def plotxy(
2936
+ data: pd.DataFrame = None,
2937
+ x=None,
2938
+ y=None,
2939
+ ax=None,
2940
+ kind: Union[str, list] = None, # Specify the kind of plot
2877
2941
  verbose=False,
2878
- # kws_figsets:dict=None,
2879
2942
  **kwargs,
2880
2943
  ):
2881
2944
  """
2882
- e.g., plot_xy(data=data_log, x="Component_1", y="Component_2", hue="Cluster",kind='scater)
2945
+ e.g., plotxy(data=data_log, x="Component_1", y="Component_2", hue="Cluster",kind='scater)
2883
2946
  Create a variety of plots based on the kind parameter.
2884
2947
 
2885
2948
  Parameters:
@@ -2942,10 +3005,10 @@ def plot_xy(
2942
3005
  kws_figsets = v_arg
2943
3006
  kwargs.pop(k_arg, None)
2944
3007
  break
2945
- kws_text = {}
3008
+ kws_add_text = {}
2946
3009
  for k_arg, v_arg in kwargs.items():
2947
- if "add" in k_arg and all(["t" in k_arg, "x" in k_arg]): # add_text
2948
- kws_text = v_arg
3010
+ if "add" in k_arg and "text" in k_arg: # add_text
3011
+ kws_add_text = v_arg
2949
3012
  kwargs.pop(k_arg, None)
2950
3013
  break
2951
3014
 
@@ -2993,6 +3056,7 @@ def plot_xy(
2993
3056
  ax = stdshade(ax=ax, **kwargs)
2994
3057
  elif k == "scatterplot":
2995
3058
  kws_scatter = kwargs.pop("kws_scatter", kwargs)
3059
+ hue = kwargs.pop("hue", None)
2996
3060
  palette = kws_scatter.pop(
2997
3061
  "palette",
2998
3062
  (
@@ -3029,7 +3093,8 @@ def plot_xy(
3029
3093
  ax = sns.rugplot(data=data, x=x, ax=ax, **kws_rug)
3030
3094
  elif k == "stripplot":
3031
3095
  kws_strip = kwargs.pop("kws_strip", kwargs)
3032
- ax = sns.stripplot(data=data, x=x, y=y, ax=ax, **kws_strip)
3096
+ dodge = kws_strip.pop("dodge", True)
3097
+ ax = sns.stripplot(data=data, x=x, y=y, ax=ax, dodge=dodge, **kws_strip)
3033
3098
  elif k == "swarmplot":
3034
3099
  kws_swarm = kwargs.pop("kws_swarm", kwargs)
3035
3100
  ax = sns.swarmplot(data=data, x=x, y=y, ax=ax, **kws_swarm)
@@ -3050,6 +3115,8 @@ def plot_xy(
3050
3115
  ax = sns.barplot(data=data, x=x, y=y, ax=ax, **kws_bar)
3051
3116
  elif k == "countplot":
3052
3117
  kws_count = kwargs.pop("kws_count", kwargs)
3118
+ if not kws_count.get("hue",None):
3119
+ kws_count.pop("palette",None)
3053
3120
  ax = sns.countplot(data=data, x=x, ax=ax, **kws_count)
3054
3121
  elif k == "regplot":
3055
3122
  kws_reg = kwargs.pop("kws_reg", kwargs)
@@ -3062,7 +3129,8 @@ def plot_xy(
3062
3129
  ax = sns.lineplot(ax=ax, data=data, x=x, y=y, **kws_line)
3063
3130
 
3064
3131
  figsets(ax=ax, **kws_figsets)
3065
- add_text(ax=ax, **kws_text)
3132
+ print(kws_add_text)
3133
+ add_text(ax=ax, **kws_add_text) if kws_add_text else None
3066
3134
  print(k, " ⤵ ")
3067
3135
  print(default_settings[k])
3068
3136
  print(
@@ -3077,14 +3145,14 @@ def plot_xy(
3077
3145
 
3078
3146
 
3079
3147
  def volcano(
3080
- data,
3081
- x,
3082
- y,
3148
+ data:pd.DataFrame,
3149
+ x:str,
3150
+ y:str,
3083
3151
  gene_col=None,
3084
3152
  top_genes=5,
3085
3153
  thr_x=np.log2(1.5),
3086
3154
  thr_y=-np.log10(0.05),
3087
- colors=("#e70b0b", "#0d26e3", "#b8bbbe"),
3155
+ colors=("#00BFFF", "#9d9a9a", "#FF3030"),
3088
3156
  s=20,
3089
3157
  fill=True, # plot filled scatter
3090
3158
  facecolor="none",
@@ -3094,8 +3162,8 @@ def volcano(
3094
3162
  legend=False,
3095
3163
  ax=None,
3096
3164
  verbose=False,
3097
- kws_arrow=None,
3098
- kws_text=None,
3165
+ kws_text=dict(fontsize=10, color="k"),
3166
+ kws_arrow=dict(style="-", color="k", lw=0.5),
3099
3167
  **kwargs,
3100
3168
  ):
3101
3169
  """
@@ -3220,55 +3288,55 @@ def volcano(
3220
3288
  fontname = kws_text.pop("fontname", "Arial")
3221
3289
  textcolor = kws_text.pop("color", "k")
3222
3290
  fontsize = kws_text.pop("fontsize", 10)
3223
- for i in range(sele_gene.shape[0]):
3224
- if isinstance(textcolor, list): # be consistant with dots's color
3225
- textcolor = colors[0] if sele_gene[x].iloc[i] > 0 else colors[1]
3226
- texts.append(
3227
- plt.text(
3228
- x=sele_gene[x].iloc[i],
3229
- y=sele_gene[y].iloc[i],
3230
- s=sele_gene[gene_col].iloc[i],
3231
- fontdict={
3232
- "fontsize": fontsize,
3233
- "color": textcolor,
3234
- "fontname": fontname,
3235
- },
3291
+ for i in range(sele_gene.shape[0]):
3292
+ if isinstance(textcolor, list): # be consistant with dots's color
3293
+ textcolor = colors[0] if sele_gene[x].iloc[i] > 0 else colors[1]
3294
+ texts.append(
3295
+ plt.text(
3296
+ x=sele_gene[x].iloc[i],
3297
+ y=sele_gene[y].iloc[i],
3298
+ s=sele_gene[gene_col].iloc[i],
3299
+ fontdict={
3300
+ "fontsize": fontsize,
3301
+ "color": textcolor,
3302
+ "fontname": fontname,
3303
+ },
3304
+ )
3236
3305
  )
3237
- )
3238
3306
 
3239
- arrowstyles = [
3240
- "-",
3241
- "->",
3242
- "-[",
3243
- "|->",
3244
- "<-",
3245
- "<->",
3246
- "<|-",
3247
- "<|-|>",
3248
- "-|>",
3249
- "-[ ",
3250
- "fancy",
3251
- "simple",
3252
- "wedge",
3253
- ]
3254
- arrowstyle = kws_arrow.pop("style", "-")
3255
- arrowcolor = kws_arrow.pop("color", "0.5")
3256
- arrowlinewidth = kws_arrow.pop("lw", 0.5)
3257
- shrinkA = kws_arrow.pop("shrinkA", 5)
3258
- shrinkB = kws_arrow.pop("shrinkB", 5)
3259
- arrowstyle = strcmp(arrowstyle, arrowstyles)[0]
3260
- adjust_text(
3261
- texts,
3262
- expand_text=(1.05, 1.2),
3263
- arrowprops=dict(
3264
- arrowstyle=arrowstyle,
3265
- color=arrowcolor,
3266
- lw=arrowlinewidth,
3267
- shrinkA=shrinkA,
3268
- shrinkB=shrinkB,
3269
- **kws_arrow,
3270
- ),
3271
- )
3307
+ arrowstyles = [
3308
+ "-",
3309
+ "->",
3310
+ "-[",
3311
+ "|->",
3312
+ "<-",
3313
+ "<->",
3314
+ "<|-",
3315
+ "<|-|>",
3316
+ "-|>",
3317
+ "-[ ",
3318
+ "fancy",
3319
+ "simple",
3320
+ "wedge",
3321
+ ]
3322
+ arrowstyle = kws_arrow.pop("style", "-")
3323
+ arrowcolor = kws_arrow.pop("color", "0.5")
3324
+ arrowlinewidth = kws_arrow.pop("lw", 0.5)
3325
+ shrinkA = kws_arrow.pop("shrinkA", 5)
3326
+ shrinkB = kws_arrow.pop("shrinkB", 5)
3327
+ arrowstyle = strcmp(arrowstyle, arrowstyles)[0]
3328
+ adjust_text(
3329
+ texts,
3330
+ expand_text=(1.05, 1.2),
3331
+ arrowprops=dict(
3332
+ arrowstyle=arrowstyle,
3333
+ color=arrowcolor,
3334
+ lw=arrowlinewidth,
3335
+ shrinkA=shrinkA,
3336
+ shrinkB=shrinkB,
3337
+ **kws_arrow,
3338
+ ),
3339
+ )
3272
3340
 
3273
3341
  figsets(**kws_figsets)
3274
3342
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2ls
3
- Version: 0.2.4
3
+ Version: 0.2.4.2
4
4
  Summary: py(thon)2(too)ls
5
5
  Author: Jianfeng
6
6
  Author-email: Jianfeng.Liu0413@gmail.com
@@ -173,6 +173,7 @@ py2ls/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
173
173
  py2ls/README.md,sha256=CwvJWAnSXnCnrVHlnEbrxxi6MbjbE_MT6DH2D53S818,11572
174
174
  py2ls/__init__.py,sha256=Nn8jTIvySX7t7DMJ8VNRVctTStgXGjHldOIdZ35PdW8,165
175
175
  py2ls/batman.py,sha256=E7gYofbDzN7S5oCmO_dd5Z1bxxhoYMJSD6s-VaF388E,11398
176
+ py2ls/bio.py,sha256=5q7T_LXmDg0MJoKXwO0kWnfbpshXNvUR5kCnYyLqm2w,10711
176
177
  py2ls/brain_atlas.py,sha256=w1o5EelRjq89zuFJUNSz4Da8HnTCwAwDAZ4NU4a-bAY,5486
177
178
  py2ls/chat.py,sha256=Yr22GoIvoWhpV3m4fdwV_I0Mn77La346_ymSinR-ORA,3793
178
179
  py2ls/correlators.py,sha256=RbOaJIPLCHJtUm5SFi_4dCJ7VFUPWR0PErfK3K26ad4,18243
@@ -203,23 +204,24 @@ py2ls/data/styles/style6.json,sha256=tu-MYOT9x5Rorc-2IK6sy-J-frmz0RNdm65XAsDQKX4
203
204
  py2ls/data/styles/style7.json,sha256=StdUFwIVrS7T_6CDrADHMorzc0WZFWBM7IyYdO1TPHg,4447
204
205
  py2ls/data/styles/style8.json,sha256=8XUgkZtew8ebvjbAHlDHCSWUqNra3ktDvMCO4vNh-CM,4456
205
206
  py2ls/data/styles/style9.json,sha256=PLxvntbH_kfzZlnCTtCEAUVBGi5m6Lngb9C01rArQog,4769
206
- py2ls/data/usages_pd.json,sha256=A76y7lr28BUBdggFN_50r-4My3Q51M_3y0ZcQ4LHSco,15077
207
+ py2ls/data/usages_pd copy.json,sha256=cS2fYSKvSC274uAw1l6eMPGzLMvZt184dfbcuUiErmw,197313
208
+ py2ls/data/usages_pd.json,sha256=4DgbPahF4G5Hd6G0TQurb6dBRVey67lpKdgK6A01Tww,266818
207
209
  py2ls/data/usages_sns.json,sha256=3OTu6T7n9HbQaFkz-UPMJ_9-Ug6Xjf7q5aDIvZ_6cHk,9246
208
210
  py2ls/db2ls.py,sha256=MMfFX47aIPIyu7fU9aPvX9lbPRPYOpJ_VXwlnWk-8qo,13615
209
211
  py2ls/doc.py,sha256=xN3g1OWfoaGUhikbJ0NqbN5eKy1VZVvWwRlhHMgyVEc,4243
210
212
  py2ls/export_requirements.py,sha256=x2WgUF0jYKz9GfA1MVKN-MdsM-oQ8yUeC6Ua8oCymio,2325
211
- py2ls/fetch_update.py,sha256=jh2MQHREpCqzYhDmEnMpuIvQVf4_wD9pDdIziXoFE3E,4055
213
+ py2ls/fetch_update.py,sha256=9LXj661GpCEFII2wx_99aINYctDiHni6DOruDs_fdt8,4752
212
214
  py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
213
215
  py2ls/ich2ls.py,sha256=3E9R8oVpyYZXH5PiIQgT3CN5NxLe4Dwtm2LwaeacE6I,21381
214
- py2ls/ips.py,sha256=92b5_p1EM0VRsEylXln7oaI7eLmtcC3GkBcEHFTUkIU,199481
216
+ py2ls/ips.py,sha256=46nrt6RRl8Lc-tMh03dRqxF4nUlLfMElnETE1ipu-DM,210309
215
217
  py2ls/netfinder.py,sha256=LwBkGITB_4BTNtY6RlKdEZVFW6epzMWlnqy2g03KtyU,56117
216
218
  py2ls/ocr.py,sha256=5lhUbJufIKRSOL6wAWVLEo8TqMYSjoI_Q-IO-_4u3DE,31419
217
- py2ls/plot.py,sha256=dxZeD27TZMzccN8_kyqSJf72PdZJk45gLuTYAeDq81I,131906
219
+ py2ls/plot.py,sha256=A4NiRDItVyrc80qPtLgT1mpzvebU_iMVVownjsu_YFc,135976
218
220
  py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
219
221
  py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso68,52145
220
222
  py2ls/stats.py,sha256=DMoJd8Z5YV9T1wB-4P52F5K5scfVK55DT8UP4Twcebo,38627
221
223
  py2ls/translator.py,sha256=zBeq4pYZeroqw3DT-5g7uHfVqKd-EQptT6LJ-Adi8JY,34244
222
224
  py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
223
- py2ls-0.2.4.dist-info/METADATA,sha256=-i9MH0eTedNkRUR6XQuj6rikJRNwp9U2eA1CskY6X1Y,20036
224
- py2ls-0.2.4.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
225
- py2ls-0.2.4.dist-info/RECORD,,
225
+ py2ls-0.2.4.2.dist-info/METADATA,sha256=_YQg86nAdjPWqkaIrH6p9nSPhjNHbY1AU0BGV6o3wU0,20038
226
+ py2ls-0.2.4.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
227
+ py2ls-0.2.4.2.dist-info/RECORD,,
File without changes