Skip to content

Commit

Permalink
Merge branch 'main' into documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Laplusdestiny committed Jul 13, 2024
2 parents 7ad57fa + f1f69d4 commit 0f15a31
Show file tree
Hide file tree
Showing 6 changed files with 427 additions and 248 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- main
- update_build_procedure
- surface

jobs:
Unit-test:
Expand All @@ -29,6 +29,6 @@ jobs:
run: |
poetry run pytest test --cov=./plotly_extend_wrapper --cov-report=xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
13 changes: 13 additions & 0 deletions codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
coverage:
status:
project:
default:
target: 100%
threshold: 1%
comment: # this is a top-level key
layout: " diff, flags, files"
behavior: default
require_changes: false # if true: only post the comment if coverage changes
require_base: false # [true :: must have a base report to post]
require_head: true # [true :: must have a head report to post]
hide_project_coverage: false # [true :: only show coverage on the git diff]
53 changes: 53 additions & 0 deletions plotly_extend_wrapper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from plotly.subplots import make_subplots
import pandas as pd
from plotly_extend_wrapper.common import check_directory
from plotly import graph_objects as go
from scipy.interpolate import griddata
import numpy as np


def Plot_pie(data: pd.DataFrame, target: str, **kwargs):
Expand Down Expand Up @@ -369,3 +372,53 @@ def Plot_bubble_chart_with_line(
subfig.layout.yaxis.title = ytitle
subfig.update_layout(**kwargs)
return subfig


def Plot_surface(
df: pd.DataFrame,
x: str,
y: str,
z: str,
fill_value=0,
smoothing=False,
smooth_point_num=100,
title=None,
height=None,
width=None,
**kwargs,
):
def smooth_df(x: np.ndarray, y: np.ndarray, z: np.ndarray, num: int):
xi = np.linspace(x.min(), x.max(), num)
yi = np.linspace(y.min(), y.max(), num)
xi, yi = np.meshgrid(xi, yi)
zi = griddata((x,y), z, (xi.ravel(), yi.ravel()), method="cubic")
zi = zi.reshape(xi.shape)
zi = np.nan_to_num(zi)
return xi, yi, zi

if smoothing:
X = df[x].values
Y = df[y].values
Z = df[z].values
X, Y, Z = smooth_df(X, Y, Z, smooth_point_num)
else:
pivot_df = pd.pivot_table(df, index=x, columns=y, values=z, fill_value=fill_value)

X = pivot_df.columns.values
Y = pivot_df.index.values
Z = pivot_df.values


data = [go.Surface(x=X, y=Y, z=Z)]
layout = go.Layout(
title=title,
scene=dict(
xaxis=dict(title=y), # need to be replaced
yaxis=dict(title=x),
zaxis=dict(title=z),
),
height=height,
width=width,
)
fig = go.Figure(data=data, layout=layout)
return fig
Loading

0 comments on commit 0f15a31

Please sign in to comment.