Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on:
workflow_dispatch: # makes it possible to run the workflow manually
push:
branches:
- main

permissions:
contents: write
pull-requests: write

name: release-please

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4.2.0
id: release
with:
token: ${{ secrets.RELEASE_PLEASE_ACCESS_TOKEN }}
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "1.3.3"
}
1 change: 1 addition & 0 deletions docs/usage/single_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ plot_one_group_bar_figure(
width=0.5,
dots_size=15,
colors=["#4573a5", "orange"],
color_alpha=0.7,
errorbar_type="sd",
edgecolor="r",
)
Expand Down
Binary file modified docs/usage/single_group_files/single_group_12_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion overrides/main.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}

{% block announce %}
<strong>📢 Announcement Bar. </strong>
<strong>📢 公告栏。Announcement Bar. </strong>
{% endblock %}
10 changes: 10 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"packages": {
".": {
"release-type": "python",
"include-component-in-tag": false,
"skip-tag-prefix": true
}
},
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
}
18 changes: 12 additions & 6 deletions src/plotfig/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy.typing as npt
from matplotlib.axes import Axes
from matplotlib.ticker import FuncFormatter, ScalarFormatter
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.colors import LinearSegmentedColormap, to_rgba
from matplotlib.patches import Polygon
from scipy import stats

Expand Down Expand Up @@ -225,6 +225,7 @@ def plot_one_group_bar_figure(
labels_name: list[str] | None = None,
width: Num = 0.5,
colors: list[str] | None = None,
color_alpha: Num = 1,
edgecolor: str | None = None,
gradient_color: bool = False,
colors_start=None,
Expand Down Expand Up @@ -254,6 +255,7 @@ def plot_one_group_bar_figure(
labels_name (list[str] | None, optional): 每个数据集对应的标签。默认为 None,使用索引作为标签。
width (Num, optional): 柱子的宽度。默认为 0.5。
colors (list[str] | None, optional): 每个柱子的颜色列表。若为 None,使用默认灰色。
color_alpha (Num, optional): 颜色透明度,取值范围为 0(完全透明)到 1(完全不透明)。使用 gradient_color 时该参数无效。默认为 1。
edgecolor (str | None, optional): 柱子的边缘颜色。默认为 None,即不特别设置。
gradient_color (bool, optional): 是否为柱子启用渐变色填充。默认为 False。
colors_start (list[str] | None, optional): 渐变色的起始颜色列表。用于 gradient_color=True。
Expand Down Expand Up @@ -317,7 +319,7 @@ def plot_one_group_bar_figure(
ax.imshow(gradient, aspect="auto", cmap=cmap, extent=extent, zorder=0)
else:
ax.bar(
x_positions, means, width=width, color=colors, alpha=1, edgecolor=edgecolor
x_positions, means, width=width, color=colors, alpha=color_alpha, edgecolor=edgecolor
)

ax.errorbar(
Expand Down Expand Up @@ -385,6 +387,7 @@ def plot_one_group_violin_figure(
ax: Axes | None = None,
width: Num = 0.8,
colors: list[str] | None = None,
color_alpha: Num = 1,
gradient_color: bool = False,
colors_start: list[str] | None = None,
colors_end: list[str] | None = None,
Expand All @@ -411,6 +414,7 @@ def plot_one_group_violin_figure(
ax (Axes | None, optional): matplotlib 的 Axes 对象,用于绘图。默认为 None,使用当前 Axes。
width (Num, optional): 小提琴图的总宽度。默认为 0.8。
colors (list[str] | None, optional): 每个小提琴的颜色。若为 None,使用默认灰色。
color_alpha (Num, optional): 颜色透明度,取值范围为 0(完全透明)到 1(完全不透明)。使用 gradient_color 时该参数无效。默认为 1。
gradient_color (bool, optional): 是否启用渐变色填充。默认为 False。
colors_start (list[str] | None, optional): 渐变起始颜色列表,对应每组数据。
colors_end (list[str] | None, optional): 渐变结束颜色列表,对应每组数据。
Expand Down Expand Up @@ -438,7 +442,7 @@ def plot_one_group_violin_figure(
labels_name = labels_name or [str(i) for i in range(len(data))]
colors = colors or ["gray"] * len(data)

def draw_gradient_violin(ax, data, pos, width=width, c1="red", c2="blue"):
def _draw_gradient_violin(ax, data, pos, width=width, c1="red", c2="blue", color_alpha=1):
# KDE估计
kde = stats.gaussian_kde(data)
buffer = (max(data) - min(data)) / 5
Expand All @@ -459,10 +463,12 @@ def draw_gradient_violin(ax, data, pos, width=width, c1="red", c2="blue"):
grad_height = 300
gradient = np.linspace(0, 1, grad_width)
if c1 == c2:
cmap = LinearSegmentedColormap.from_list("cmap", [c1, c2])
rgba = to_rgba(c1, alpha=color_alpha)
cmap = LinearSegmentedColormap.from_list("cmap", [rgba, rgba])
gradient_rgb = plt.get_cmap(cmap)(gradient)
else:
cmap = LinearSegmentedColormap.from_list("cmap", [c1, "white", c2])
gradient_rgb = plt.get_cmap(cmap)(gradient)[..., :3]
gradient_rgb = plt.get_cmap(cmap)(gradient)[..., :3]
gradient_img = np.tile(gradient_rgb, (grad_height, 1, 1))
# 显示图像并裁剪成violin形状
im = ax.imshow(
Expand Down Expand Up @@ -508,7 +514,7 @@ def draw_gradient_violin(ax, data, pos, width=width, c1="red", c2="blue"):
c2 = colors_end[i]
else:
c1 = c2 = colors[i]
ymax, ymin = draw_gradient_violin(ax, d, pos=i, c1=c1, c2=c2)
ymax, ymin = _draw_gradient_violin(ax, d, pos=i, c1=c1, c2=c2, color_alpha=color_alpha)
ymax_lst.append(ymax)
ymin_lst.append(ymin)
ymax = max(ymax_lst)
Expand Down