plotly-extend-wrapper 1.3.0__py3-none-any.whl → 1.4.0__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.
@@ -1,12 +1,22 @@
1
1
  from pathlib import Path
2
+ from plotly.io import get_chrome
2
3
 
3
4
 
4
- def check_directory(file_p):
5
- file_p = Path(file_p)
6
- if file_p.suffix == "":
7
- dir_p = file_p
5
+ def check_directory(file_path):
6
+ """
7
+ Ensures that the directory for the given file path exists, creating it if necessary.
8
+
9
+ Args:
10
+ file_path (str or Path): The file path for which to check the directory.
11
+
12
+ Returns:
13
+ Path: The resolved absolute path of the given file path.
14
+ """
15
+ file_path = Path(file_path)
16
+ if not file_path.suffix:
17
+ dir_p = file_path
8
18
  else:
9
- dir_p = file_p.parent
19
+ dir_p = file_path.parent
10
20
  if not dir_p.is_dir():
11
- dir_p.mkdir(parents=True)
12
- return file_p.resolve()
21
+ dir_p.mkdir(parents=True, exist_ok=True)
22
+ return file_path.resolve()
@@ -6,15 +6,52 @@ from plotly import graph_objects as go
6
6
  from scipy.interpolate import griddata
7
7
  import numpy as np
8
8
  from copy import deepcopy
9
+ from typing import Union
9
10
 
11
+ # Optional polars support
12
+ try:
13
+ import polars as pl
14
+ POLARS_AVAILABLE = True
15
+ except ImportError:
16
+ POLARS_AVAILABLE = False
17
+ pl = None
10
18
 
11
- def Plot_pie(data: pd.DataFrame, target: str, **kwargs):
19
+
20
+ def _normalize_dataframe(data) -> pd.DataFrame:
21
+ """
22
+ Convert various DataFrame formats to pandas.DataFrame.
23
+
24
+ Supports pandas.DataFrame, polars.DataFrame, and polars.LazyFrame.
25
+
26
+ Parameters
27
+ ----------
28
+ data : pd.DataFrame, pl.DataFrame, or pl.LazyFrame
29
+ Input data frame
30
+
31
+ Returns
32
+ -------
33
+ pd.DataFrame
34
+ Normalized pandas DataFrame
35
+ """
36
+ if POLARS_AVAILABLE and pl is not None:
37
+ if isinstance(data, pl.LazyFrame):
38
+ return data.collect().to_pandas()
39
+ elif isinstance(data, pl.DataFrame):
40
+ return data.to_pandas()
41
+
42
+ if isinstance(data, pd.DataFrame):
43
+ return data
44
+
45
+ raise TypeError(f"Unsupported data type: {type(data)}. Expected pandas.DataFrame, polars.DataFrame, or polars.LazyFrame.")
46
+
47
+
48
+ def Plot_pie(data: Union[pd.DataFrame, "pl.DataFrame", "pl.LazyFrame"], target: str, **kwargs):
12
49
  """Make pie plot
13
50
 
14
51
  Parameters
15
52
  ----------
16
- data : pd.DataFrame
17
- pandas.DataFrame included data to make pie chart
53
+ data : pd.DataFrame, pl.DataFrame, or pl.LazyFrame
54
+ DataFrame included data to make pie chart
18
55
  target : str
19
56
  String which column you would like to use for pie chart
20
57
 
@@ -23,17 +60,18 @@ def Plot_pie(data: pd.DataFrame, target: str, **kwargs):
23
60
  plotly.graph_objects
24
61
  Object of pie chart
25
62
  """
63
+ data = _normalize_dataframe(data)
26
64
  vc = data[target].value_counts().reset_index(name="count")
27
65
  return px.pie(vc, names=target, values="count", **kwargs)
28
66
 
29
67
 
30
- def Plot_sunburst(data: pd.DataFrame, groups: list, **kwargs):
68
+ def Plot_sunburst(data: Union[pd.DataFrame, "pl.DataFrame", "pl.LazyFrame"], groups: list, **kwargs):
31
69
  """Make sunburst plot
32
70
 
33
71
  Parameters
34
72
  ----------
35
- data : pd.DataFrame
36
- pandas.DataFrame included data to make sunburst chart
73
+ data : pd.DataFrame, pl.DataFrame, or pl.LazyFrame
74
+ DataFrame included data to make sunburst chart
37
75
  groups : list
38
76
  Strings list of group
39
77
  Changed when you replace the order
@@ -43,6 +81,7 @@ def Plot_sunburst(data: pd.DataFrame, groups: list, **kwargs):
43
81
  plotly.graph_objects
44
82
  Object of sunburst chart
45
83
  """
84
+ data = _normalize_dataframe(data)
46
85
  vc = data.value_counts(subset=groups).reset_index(name="count")
47
86
  return px.sunburst(vc, path=groups, values="count", **kwargs)
48
87
 
@@ -69,8 +108,8 @@ class Plot_bubble_chart:
69
108
 
70
109
  Parameters
71
110
  ----------
72
- df : pandas.DataFrame
73
- pandas.DataFrame included data to make plot
111
+ df : pandas.DataFrame, pl.DataFrame, or pl.LazyFrame
112
+ DataFrame included data to make plot
74
113
  x : str
75
114
  X-axis column's name
76
115
  y : str
@@ -92,6 +131,7 @@ class Plot_bubble_chart:
92
131
  offset : int, optional
93
132
  Offset value for bubble size, by default 0
94
133
  """
134
+ df = _normalize_dataframe(df)
95
135
  self.df = df.copy()
96
136
  self.x = x
97
137
  self.y = y
@@ -188,7 +228,7 @@ class Plot_bubble_chart:
188
228
 
189
229
 
190
230
  def Plot_line(
191
- df: pd.DataFrame,
231
+ df: Union[pd.DataFrame, "pl.DataFrame", "pl.LazyFrame"],
192
232
  x: str,
193
233
  y: list,
194
234
  secondary_y: list,
@@ -210,7 +250,7 @@ def Plot_line(
210
250
 
211
251
  Parameters
212
252
  ----------
213
- df : pd.DataFrame
253
+ df : pd.DataFrame, pl.DataFrame, or pl.LazyFrame
214
254
  Original dataframe
215
255
  x : str
216
256
  X-axis column name
@@ -252,6 +292,8 @@ def Plot_line(
252
292
 
253
293
  random.seed(42)
254
294
 
295
+ df = _normalize_dataframe(df)
296
+
255
297
  def pick_color():
256
298
  return ["#" + "".join([random.choice("0123456789ABCDEF") for j in range(6)])][0]
257
299
 
@@ -402,7 +444,7 @@ def Plot_bubble_chart_with_line(
402
444
 
403
445
 
404
446
  def Plot_surface(
405
- df: pd.DataFrame,
447
+ df: Union[pd.DataFrame, "pl.DataFrame", "pl.LazyFrame"],
406
448
  x: str,
407
449
  y: str,
408
450
  z: str,
@@ -414,6 +456,26 @@ def Plot_surface(
414
456
  width=None,
415
457
  **kwargs,
416
458
  ):
459
+ """
460
+ Generates a 3D surface plot using Plotly.
461
+
462
+ Parameters:
463
+ df (pd.DataFrame, pl.DataFrame, or pl.LazyFrame): The input data frame containing the data to plot.
464
+ x (str): The column name for the x-axis.
465
+ y (str): The column name for the y-axis.
466
+ z (str): The column name for the z-axis.
467
+ fill_value (int, optional): The value to fill missing data in the pivot table. Default is 0.
468
+ smoothing (bool, optional): Whether to apply smoothing to the data. Default is False.
469
+ smooth_point_num (int, optional): The number of points to use for smoothing. Default is 100.
470
+ title (str, optional): The title of the plot. Default is None.
471
+ height (int, optional): The height of the plot. Default is None.
472
+ width (int, optional): The width of the plot. Default is None.
473
+ **kwargs: Additional keyword arguments to pass to the plot.
474
+
475
+ Returns:
476
+ plotly.graph_objs._figure.Figure: The generated 3D surface plot.
477
+ """
478
+
417
479
  def smooth_df(x: np.ndarray, y: np.ndarray, z: np.ndarray, num: int):
418
480
  xi = np.linspace(x.min(), x.max(), num)
419
481
  yi = np.linspace(y.min(), y.max(), num)
@@ -423,6 +485,8 @@ def Plot_surface(
423
485
  zi = np.nan_to_num(zi)
424
486
  return xi, yi, zi
425
487
 
488
+ df = _normalize_dataframe(df)
489
+
426
490
  if smoothing:
427
491
  X = df[x].values
428
492
  Y = df[y].values
@@ -430,7 +494,8 @@ def Plot_surface(
430
494
  X, Y, Z = smooth_df(X, Y, Z, smooth_point_num)
431
495
  else:
432
496
  pivot_df = pd.pivot_table(
433
- df, index=x, columns=y, values=z, fill_value=fill_value)
497
+ df, index=x, columns=y, values=z, fill_value=fill_value
498
+ )
434
499
 
435
500
  X = pivot_df.columns.values
436
501
  Y = pivot_df.index.values
@@ -440,7 +505,7 @@ def Plot_surface(
440
505
  layout = go.Layout(
441
506
  title=title,
442
507
  scene=dict(
443
- xaxis=dict(title=y), # need to be replaced
508
+ xaxis=dict(title=y), # need to be replaced
444
509
  yaxis=dict(title=x),
445
510
  zaxis=dict(title=z),
446
511
  ),
@@ -1,17 +1,20 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotly-extend-wrapper
3
- Version: 1.3.0
3
+ Version: 1.4.0
4
4
  Author-email: Laplusdestiny <prayonshootingstars@gmail.com>
5
- License-File: LICENSE
6
5
  Requires-Python: >=3.9
7
- Requires-Dist: kaleido==0.2.1
8
- Requires-Dist: nbformat>=4.2.0
9
- Requires-Dist: numpy>=1.24.0
10
- Requires-Dist: pandas>=2.0.0
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
11
8
  Requires-Dist: plotly>=5.12.0
9
+ Requires-Dist: kaleido>=0.2.1
12
10
  Requires-Dist: pyarrow>=10.0.0
11
+ Requires-Dist: pandas>=2.0.0
13
12
  Requires-Dist: scipy>=1.8.0
14
- Description-Content-Type: text/markdown
13
+ Requires-Dist: numpy>=1.24.0
14
+ Requires-Dist: nbformat>=4.2.0
15
+ Provides-Extra: polars
16
+ Requires-Dist: polars>=0.20.0; extra == "polars"
17
+ Dynamic: license-file
15
18
 
16
19
  # plotly_extend_wrapper
17
20
 
@@ -22,7 +25,19 @@ Description-Content-Type: text/markdown
22
25
 
23
26
  Extended Python library for Plotly
24
27
 
25
- You can make plot simply
28
+ - **Simple Interface**: Create complex visualizations with just a few lines of code
29
+ - **Pandas Integration**: Seamless integration with pandas DataFrames
30
+ - **Multiple Plot Types**: Support for various chart types including pie charts, sunburst diagrams, and 3D surfaces
31
+ - **Customization**: Easy plot customization through a unified interface
32
+ - **Automatic Layout**: Smart default settings for common plot configurations
33
+
34
+ For detailed documentation and examples, visit our [Documentation](https://laplusdestiny.github.io/plotly_extend_wrapper/)
35
+
36
+ ## Install
37
+
38
+ ``` bash
39
+ pip install plotly-extend-wrapper
40
+ ```
26
41
 
27
42
  ## Requirement
28
43
 
@@ -37,3 +52,9 @@ You can make plot simply
37
52
  If there are some bugs, please make issue to tell me!
38
53
 
39
54
  [![GitHub issues](https://img.shields.io/github/issues/Laplusdestiny/plotly_extend_wrapper?logo=github)](https://github.com/Laplusdestiny/plotly_extend_wrapper/issues)
55
+
56
+ ## License
57
+
58
+ MIT License
59
+
60
+ [![GitHub](https://img.shields.io/github/license/Laplusdestiny/plotly_extend_wrapper?logo=github)](https://github.com/Laplusdestiny/plotly_extend_wrapper?tab=MIT-1-ov-file#MIT-1-ov-file)
@@ -0,0 +1,9 @@
1
+ plotly_extend_wrapper/__init__.py,sha256=qbQNutZVb9yrOGqDwDekSe3t1kkMyfWCQiZRrzogJgM,154
2
+ plotly_extend_wrapper/common.py,sha256=HyApL_BOUrLbHIzp-k9Gu5W2DwVwu9-_fLs0qeQFjTA,605
3
+ plotly_extend_wrapper/updater.py,sha256=Q-O5FC7z_y1Xel24rBaaiN7MPOQqOy5wG7bpth_VVts,2510
4
+ plotly_extend_wrapper/wrapper.py,sha256=Tig9oWIcvmaplYXyI3G1M7Ppg626lZNhi-0OOKxF0Mw,15585
5
+ plotly_extend_wrapper-1.4.0.dist-info/licenses/LICENSE,sha256=LanHfVWzsvc8f0WfJlk8s_qAhDW1RdNJMYDjDMJvl1Y,1070
6
+ plotly_extend_wrapper-1.4.0.dist-info/METADATA,sha256=dC2dAzPpXJGMabYSrOky-0nOdstW0G9YaV_yQhQmj7M,2428
7
+ plotly_extend_wrapper-1.4.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
8
+ plotly_extend_wrapper-1.4.0.dist-info/top_level.txt,sha256=w9ZAZejWegkpPPQUHPZLHVVmlsA3DEDU8yJaE-LadPQ,22
9
+ plotly_extend_wrapper-1.4.0.dist-info/RECORD,,
@@ -1,4 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
2
+ Generator: setuptools (82.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ plotly_extend_wrapper
@@ -1,8 +0,0 @@
1
- plotly_extend_wrapper/__init__.py,sha256=qbQNutZVb9yrOGqDwDekSe3t1kkMyfWCQiZRrzogJgM,154
2
- plotly_extend_wrapper/common.py,sha256=il-4w-f7gsgKuHKHyy-lAbema6-ADdRFdHXZNTYSdhk,262
3
- plotly_extend_wrapper/updater.py,sha256=Q-O5FC7z_y1Xel24rBaaiN7MPOQqOy5wG7bpth_VVts,2510
4
- plotly_extend_wrapper/wrapper.py,sha256=YA8sDVYGMTE8n5-q7tLlmfUGENG8qS9BfA3eSJu-VgY,13222
5
- plotly_extend_wrapper-1.3.0.dist-info/METADATA,sha256=UnUrBrGDM1W0jdl_8pI3UCGcB3zRhoghkICCH6QhPiU,1541
6
- plotly_extend_wrapper-1.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- plotly_extend_wrapper-1.3.0.dist-info/licenses/LICENSE,sha256=LanHfVWzsvc8f0WfJlk8s_qAhDW1RdNJMYDjDMJvl1Y,1070
8
- plotly_extend_wrapper-1.3.0.dist-info/RECORD,,