py2ls 0.1.6.1__py3-none-any.whl → 0.1.6.3__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/ips.py CHANGED
@@ -879,8 +879,9 @@ def fload(fpath, kind=None, **kwargs):
879
879
  root = tree.getroot()
880
880
  return etree.tostring(root, pretty_print=True).decode()
881
881
 
882
- def load_csv(fpath, **kwargs):
883
- df = pd.read_csv(fpath, **kwargs)
882
+ def load_csv(fpath, engine='pyarrow',**kwargs):
883
+ print(f"engine={engine}")
884
+ df = pd.read_csv(fpath, engine=engine, **kwargs)
884
885
  return df
885
886
 
886
887
  def load_xlsx(fpath, **kwargs):
@@ -2011,337 +2012,6 @@ def imgsets(
2011
2012
  # show_axis=True,
2012
2013
  # )
2013
2014
 
2014
- def figsets(*args,**kwargs):
2015
- """
2016
- usage:
2017
- figsets(ax=axs[1],
2018
- ylim=[0, 10],
2019
- spine=2,
2020
- xticklabel=['wake','sleep'],
2021
- yticksdddd=np.arange(0,316,60),
2022
- labels_loc=['right','top'],
2023
- ticks=dict(
2024
- ax='x',
2025
- which='minor',
2026
- direction='out',
2027
- width=2,
2028
- length=2,
2029
- c_tick='m',
2030
- pad=5,
2031
- label_size=11),
2032
- grid=dict(which='minor',
2033
- ax='x',
2034
- alpha=.4,
2035
- c='b',
2036
- ls='-.',
2037
- lw=0.75,
2038
- ),
2039
- supertitleddddd=f'sleep druations\n(min)',
2040
- c_spine='r',
2041
- minor_ticks='xy',
2042
- style='paper',
2043
- box=['right','bottom'],
2044
- xrot=-45,
2045
- yangle=20,
2046
- font_sz = 2,
2047
- legend=dict(labels=['group_a','group_b'],
2048
- loc='upper left',
2049
- edgecolor='k',
2050
- facecolor='r',
2051
- title='title',
2052
- fancybox=1,
2053
- shadow=1,
2054
- ncols=4,
2055
- bbox_to_anchor=[-0.5,0.7],
2056
- alignment='left')
2057
- )
2058
- """
2059
- fig = plt.gcf()
2060
- fontsize = 11
2061
- fontname = "Arial"
2062
- sns_themes = ["white", "whitegrid", "dark", "darkgrid", "ticks"]
2063
- sns_contexts = ["notebook", "talk", "poster"] # now available "paper"
2064
- scienceplots_styles = ["science","nature",
2065
- "scatter","ieee","no-latex","std-colors","high-vis","bright","dark_background","science",
2066
- "high-vis","vibrant","muted","retro","grid","high-contrast","light","cjk-tc-font","cjk-kr-font",
2067
- ]
2068
- def set_step_1(ax,key, value):
2069
- if ("fo" in key) and (("size" in key) or ("sz" in key)):
2070
- fontsize=value
2071
- plt.rcParams.update({"font.size": value})
2072
- # style
2073
- if "st" in key.lower() or "th" in key.lower():
2074
- if isinstance(value, str):
2075
- if (value in plt.style.available) or (value in scienceplots_styles):
2076
- plt.style.use(value)
2077
- elif value in sns_themes:
2078
- sns.set_style(value)
2079
- elif value in sns_contexts:
2080
- sns.set_context(value)
2081
- else:
2082
- print(
2083
- f"\nWarning\n'{value}' is not a plt.style,select on below:\n{plt.style.available+sns_themes+sns_contexts+scienceplots_styles}"
2084
- )
2085
- if isinstance(value, list):
2086
- for i in value:
2087
- if (i in plt.style.available) or (i in scienceplots_styles):
2088
- plt.style.use(i)
2089
- elif i in sns_themes:
2090
- sns.set_style(i)
2091
- elif i in sns_contexts:
2092
- sns.set_context(i)
2093
- else:
2094
- print(
2095
- f"\nWarning\n'{i}' is not a plt.style,select on below:\n{plt.style.available+sns_themes+sns_contexts+scienceplots_styles}"
2096
- )
2097
- if "la" in key.lower():
2098
- if "loc" in key.lower() or "po" in key.lower():
2099
- for i in value:
2100
- if "l" in i.lower() and not 'g' in i.lower():
2101
- ax.yaxis.set_label_position("left")
2102
- if "r" in i.lower() and not 'o' in i.lower():
2103
- ax.yaxis.set_label_position("right")
2104
- if "t" in i.lower() and not 'l' in i.lower():
2105
- ax.xaxis.set_label_position("top")
2106
- if "b" in i.lower()and not 'o' in i.lower():
2107
- ax.xaxis.set_label_position("bottom")
2108
- if ("x" in key.lower()) and (
2109
- "tic" not in key.lower() and "tk" not in key.lower()
2110
- ):
2111
- ax.set_xlabel(value, fontname=fontname)
2112
- if ("y" in key.lower()) and (
2113
- "tic" not in key.lower() and "tk" not in key.lower()
2114
- ):
2115
- ax.set_ylabel(value, fontname=fontname)
2116
- if ("z" in key.lower()) and (
2117
- "tic" not in key.lower() and "tk" not in key.lower()
2118
- ):
2119
- ax.set_zlabel(value, fontname=fontname)
2120
- if key=='xlabel' and isinstance(value,dict):
2121
- ax.set_xlabel(**value)
2122
- if key=='ylabel' and isinstance(value,dict):
2123
- ax.set_ylabel(**value)
2124
- # tick location
2125
- if "tic" in key.lower() or "tk" in key.lower():
2126
- if ("loc" in key.lower()) or ("po" in key.lower()):
2127
- if isinstance(value,str):
2128
- value=[value]
2129
- if isinstance(value, list):
2130
- loc = []
2131
- for i in value:
2132
- if ("l" in i.lower()) and ("a" not in i.lower()):
2133
- ax.yaxis.set_ticks_position("left")
2134
- if "r" in i.lower():
2135
- ax.yaxis.set_ticks_position("right")
2136
- if "t" in i.lower():
2137
- ax.xaxis.set_ticks_position("top")
2138
- if "b" in i.lower():
2139
- ax.xaxis.set_ticks_position("bottom")
2140
- if i.lower() in ["a", "both", "all", "al", ":"]:
2141
- ax.xaxis.set_ticks_position("both")
2142
- ax.yaxis.set_ticks_position("both")
2143
- if i.lower() in ["xnone",'xoff',"none"]:
2144
- ax.xaxis.set_ticks_position("none")
2145
- if i.lower() in ["ynone",'yoff','none']:
2146
- ax.yaxis.set_ticks_position("none")
2147
- # ticks / labels
2148
- elif "x" in key.lower():
2149
- if value is None:
2150
- value=[]
2151
- if "la" not in key.lower():
2152
- ax.set_xticks(value)
2153
- if "la" in key.lower():
2154
- ax.set_xticklabels(value)
2155
- elif "y" in key.lower():
2156
- if value is None:
2157
- value=[]
2158
- if "la" not in key.lower():
2159
- ax.set_yticks(value)
2160
- if "la" in key.lower():
2161
- ax.set_yticklabels(value)
2162
- elif "z" in key.lower():
2163
- if value is None:
2164
- value=[]
2165
- if "la" not in key.lower():
2166
- ax.set_zticks(value)
2167
- if "la" in key.lower():
2168
- ax.set_zticklabels(value)
2169
- # rotation
2170
- if "angle" in key.lower() or ("rot" in key.lower()):
2171
- if "x" in key.lower():
2172
- ax.tick_params(axis="x", rotation=value)
2173
- if "y" in key.lower():
2174
- ax.tick_params(axis="y", rotation=value)
2175
-
2176
- if "bo" in key in key: # box setting, and ("p" in key or "l" in key):
2177
- if isinstance(value, (str, list)):
2178
- locations = []
2179
- for i in value:
2180
- if "l" in i.lower() and not 't' in i.lower():
2181
- locations.append("left")
2182
- if "r" in i.lower()and not 'o' in i.lower(): # right
2183
- locations.append("right")
2184
- if "t" in i.lower() and not 'r' in i.lower(): #top
2185
- locations.append("top")
2186
- if "b" in i.lower() and not 't' in i.lower():
2187
- locations.append("bottom")
2188
- if i.lower() in ["a", "both", "all", "al", ":"]:
2189
- [
2190
- locations.append(x)
2191
- for x in ["left", "right", "top", "bottom"]
2192
- ]
2193
- for i in value:
2194
- if i.lower() in "none":
2195
- locations = []
2196
- # check spines
2197
- for loc, spi in ax.spines.items():
2198
- if loc in locations:
2199
- spi.set_position(("outward", 0))
2200
- else:
2201
- spi.set_color("none") # no spine
2202
- if 'tick' in key.lower(): # tick ticks tick_para ={}
2203
- if isinstance(value, dict):
2204
- for k, val in value.items():
2205
- if "wh" in k.lower():
2206
- ax.tick_params(
2207
- which=val
2208
- ) # {'major', 'minor', 'both'}, default: 'major'
2209
- elif "dir" in k.lower():
2210
- ax.tick_params(direction=val) # {'in', 'out', 'inout'}
2211
- elif "len" in k.lower():# length
2212
- ax.tick_params(length=val)
2213
- elif ("wid" in k.lower()) or ("wd" in k.lower()): # width
2214
- ax.tick_params(width=val)
2215
- elif "ax" in k.lower(): # ax
2216
- ax.tick_params(axis=val) # {'x', 'y', 'both'}, default: 'both'
2217
- elif ("c" in k.lower()) and ("ect" not in k.lower()):
2218
- ax.tick_params(colors=val) # Tick color.
2219
- elif "pad" in k.lower() or 'space' in k.lower():
2220
- ax.tick_params(
2221
- pad=val
2222
- ) # float, distance in points between tick and label
2223
- elif (
2224
- ("lab" in k.lower() or 'text' in k.lower())
2225
- and ("s" in k.lower())
2226
- and ("z" in k.lower())
2227
- ): # label_size
2228
- ax.tick_params(
2229
- labelsize=val
2230
- ) # float, distance in points between tick and label
2231
-
2232
- if "mi" in key.lower() and "tic" in key.lower():# minor_ticks
2233
- if "x" in value.lower() or "x" in key.lower():
2234
- ax.xaxis.set_minor_locator(tck.AutoMinorLocator()) # ax.minorticks_on()
2235
- if "y" in value.lower() or "y" in key.lower():
2236
- ax.yaxis.set_minor_locator(
2237
- tck.AutoMinorLocator()
2238
- ) # ax.minorticks_off()
2239
- if value.lower() in ["both", ":", "all", "a", "b", "on"]:
2240
- ax.minorticks_on()
2241
- if key == "colormap" or key == "cmap":
2242
- plt.set_cmap(value)
2243
- def set_step_2(ax,key, value):
2244
- if key == "figsize":
2245
- pass
2246
- if "xlim" in key.lower():
2247
- ax.set_xlim(value)
2248
- if "ylim" in key.lower():
2249
- ax.set_ylim(value)
2250
- if "zlim" in key.lower():
2251
- ax.set_zlim(value)
2252
- if "sc" in key.lower(): #scale
2253
- if "x" in key.lower():
2254
- ax.set_xscale(value)
2255
- if "y" in key.lower():
2256
- ax.set_yscale(value)
2257
- if "z" in key.lower():
2258
- ax.set_zscale(value)
2259
- if key == "grid":
2260
- if isinstance(value, dict):
2261
- for k, val in value.items():
2262
- if "wh" in k.lower(): # which
2263
- ax.grid(
2264
- which=val
2265
- ) # {'major', 'minor', 'both'}, default: 'major'
2266
- elif "ax" in k.lower(): # ax
2267
- ax.grid(axis=val) # {'x', 'y', 'both'}, default: 'both'
2268
- elif ("c" in k.lower()) and ("ect" not in k.lower()): # c: color
2269
- ax.grid(color=val) # Tick color.
2270
- elif "l" in k.lower() and ("s" in k.lower()):# ls:line stype
2271
- ax.grid(linestyle=val)
2272
- elif "l" in k.lower() and ("w" in k.lower()): # lw: line width
2273
- ax.grid(linewidth=val)
2274
- elif "al" in k.lower():# alpha:
2275
- ax.grid(alpha=val)
2276
- else:
2277
- if value == "on" or value is True:
2278
- ax.grid(visible=True)
2279
- elif value == "off" or value is False:
2280
- ax.grid(visible=False)
2281
- if "tit" in key.lower():
2282
- if "sup" in key.lower():
2283
- plt.suptitle(value)
2284
- else:
2285
- ax.set_title(value)
2286
- if key.lower() in ["spine", "adjust", "ad", "sp", "spi", "adj","spines"]:
2287
- if isinstance(value, bool) or (value in ["go", "do", "ja", "yes"]):
2288
- if value:
2289
- adjust_spines(ax) # dafault distance=2
2290
- if isinstance(value, (float, int)):
2291
- adjust_spines(ax=ax, distance=value)
2292
- if "c" in key.lower() and ("sp" in key.lower() or "ax" in key.lower()):# spine color
2293
- for loc, spi in ax.spines.items():
2294
- spi.set_color(value)
2295
- if 'leg' in key.lower(): # legend
2296
- legend_kws = kwargs.get('legend', None)
2297
- if legend_kws:
2298
- # https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
2299
- ax.legend(**legend_kws)
2300
-
2301
- for arg in args:
2302
- if isinstance(arg,matplotlib.axes._axes.Axes):
2303
- ax=arg
2304
- args=args[1:]
2305
- ax = kwargs.get('ax',plt.gca())
2306
- if 'ax' not in locals() or ax is None:
2307
- ax=plt.gca()
2308
- for key, value in kwargs.items():
2309
- set_step_1(ax, key, value)
2310
- set_step_2(ax, key, value)
2311
- for arg in args:
2312
- if isinstance(arg, dict):
2313
- for k, val in arg.items():
2314
- set_step_1(ax,k, val)
2315
- for k, val in arg.items():
2316
- set_step_2(ax,k, val)
2317
- else:
2318
- Nargin = len(args) // 2
2319
- ax.labelFontSizeMultiplier = 1
2320
- ax.titleFontSizeMultiplier = 1
2321
- ax.set_facecolor("w")
2322
-
2323
- for ip in range(Nargin):
2324
- key = args[ip * 2].lower()
2325
- value = args[ip * 2 + 1]
2326
- set_step_1(ax,key, value)
2327
- for ip in range(Nargin):
2328
- key = args[ip * 2].lower()
2329
- value = args[ip * 2 + 1]
2330
- set_step_2(ax,key, value)
2331
- colors = [
2332
- "#474747",
2333
- "#FF2C00",
2334
- "#0C5DA5",
2335
- "#845B97",
2336
- "#58BBCC",
2337
- "#FF9500",
2338
- "#D57DBE",
2339
- ]
2340
- matplotlib.rcParams["axes.prop_cycle"] = cycler(color=colors)
2341
- if len(fig.get_axes()) > 1:
2342
- plt.tight_layout()
2343
- plt.gcf().align_labels()
2344
-
2345
2015
 
2346
2016
  def thumbnail(dir_img_list,figsize=(10,10),dpi=100, dir_save=None, kind='.png'):
2347
2017
  """