Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add width and baseline properties documentation #3358

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
80 changes: 80 additions & 0 deletions doc/_tutorial/properties.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,86 @@
")"
]
},
{
"attachments": {},
"cell_type": "raw",
"id": "b783edda",
"metadata": {},
"source": [
".. _width_property:\n",
"\n",
"width\n",
"~~~~~\n",
"\n",
"The `width` property determines the relative width of bar or dash marks. A `width` of `1.0` means that there is no gap between adjacent marks, values greater than `1.0` lead to overlapping."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fe4a0215",
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"nan = float(\"nan\")\n",
"x_bar = [0, 1, 2] + [nan] * 9\n",
"y_bar = [1, 2, 3] + [nan] * 9\n",
"\n",
"(\n",
" so.Plot()\n",
" .add(\n",
" so.Bar(color=\".8\", edgecolor=\".2\", edgewidth=2.5),\n",
" x=x_bar,\n",
" y=y_bar,\n",
" fill=True,\n",
" width=0.5,\n",
" )\n",
" .add(\n",
" so.Bar(color=\".8\", edgecolor=\".2\", edgewidth=2.5),\n",
" x=np.roll(x_bar, 3) + 5,\n",
" y=np.roll(y_bar, 3),\n",
" fill=True,\n",
" width=0.8,\n",
" )\n",
" .add(\n",
" so.Bar(color=\".8\", edgecolor=\".2\", edgewidth=2.5),\n",
" x=np.roll(x_bar, 6) + 10,\n",
" y=np.roll(y_bar, 6),\n",
" fill=True,\n",
" width=1.0,\n",
" )\n",
" .add(\n",
" so.Bar(color=\".8\", edgecolor=\".2\", edgewidth=2.5),\n",
" x=np.roll(x_bar, 9) + 15,\n",
" y=np.roll(y_bar, 9),\n",
" fill=True,\n",
" width=1.5,\n",
" ) \n",
" .theme({\n",
" **axes_style(\"ticks\"),\n",
" \"axes.spines.left\": False,\n",
" \"axes.spines.top\": False,\n",
" \"axes.spines.right\": False,\n",
" \"xtick.labelsize\": 14,\n",
" })\n",
" .layout(size=(9, 1.25), engine=None)\n",
" .scale(\n",
" fill=None,\n",
" x=so.Continuous().tick(at=[1, 6, 11, 16])\n",
" .label(\n",
" like={\n",
" 1: 0.5, 6: 0.8, 11: 1.0, 16: 1.5\n",
" }.get,\n",
" ),\n",
" y=so.Continuous().tick(count=0),\n",
" )\n",
")"
]
},
{
"cell_type": "raw",
"id": "c2ca33db-df52-4958-889a-320b4833a0d7",
Expand Down
8 changes: 8 additions & 0 deletions seaborn/_core/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ def default_range(self) -> tuple[float, float]:
return base * .5, base * 2


class Width(IntervalProperty):
"""Width for bar and dash marks as relative value."""
legend = False
normed = False


# =================================================================================== #
# Properties defined by arbitrary objects with inherently nominal scaling
# =================================================================================== #
Expand Down Expand Up @@ -832,6 +838,8 @@ def _get_values(self, scale: Scale, levels: list) -> list:
"ymin": Coordinate,
"ymax": Coordinate,
"group": Property,
"baseline": Coordinate,
"width": Width,
# TODO pattern?
# TODO gradient?
}
Expand Down