|
1190 | 1190 | "cell_type": "markdown",
|
1191 | 1191 | "metadata": {},
|
1192 | 1192 | "source": [
|
1193 |
| - "In version 0.20.0 the ability to customize the bar chart further was given. You can now have the `df.style.bar` be centered on zero or midpoint value (in addition to the already existing way of having the min value at the left side of the cell), and you can pass a list of `[color_negative, color_positive]`.\n", |
| 1193 | + "Additional keyword arguments give more control on centering and positioning, and you can pass a list of `[color_negative, color_positive]` to highlight lower and higher values.\n", |
1194 | 1194 | "\n",
|
1195 |
| - "Here's how you can change the above with the new `align='mid'` option:" |
| 1195 | + "Here's how you can change the above with the new `align` option, combined with setting `vmin` and `vmax` limits, the `width` of the figure, and underlying css `props` of cells, leaving space to display the text and the bars:" |
1196 | 1196 | ]
|
1197 | 1197 | },
|
1198 | 1198 | {
|
|
1201 | 1201 | "metadata": {},
|
1202 | 1202 | "outputs": [],
|
1203 | 1203 | "source": [
|
1204 |
| - "df2.style.bar(subset=['A', 'B'], align='mid', color=['#d65f5f', '#5fba7d'])" |
| 1204 | + "df2.style.bar(align=0, vmin=-2.5, vmax=2.5, color=['#d65f5f', '#5fba7d'],\n", |
| 1205 | + " width=60, props=\"width: 120px; border-right: 1px solid black;\").format('{:.3f}', na_rep=\"\")" |
1205 | 1206 | ]
|
1206 | 1207 | },
|
1207 | 1208 | {
|
|
1225 | 1226 | "\n",
|
1226 | 1227 | "# Test series\n",
|
1227 | 1228 | "test1 = pd.Series([-100,-60,-30,-20], name='All Negative')\n",
|
1228 |
| - "test2 = pd.Series([10,20,50,100], name='All Positive')\n", |
1229 |
| - "test3 = pd.Series([-10,-5,0,90], name='Both Pos and Neg')\n", |
| 1229 | + "test2 = pd.Series([-10,-5,0,90], name='Both Pos and Neg')\n", |
| 1230 | + "test3 = pd.Series([10,20,50,100], name='All Positive')\n", |
| 1231 | + "test4 = pd.Series([100, 103, 101, 102], name='Large Positive')\n", |
| 1232 | + "\n", |
1230 | 1233 | "\n",
|
1231 | 1234 | "head = \"\"\"\n",
|
1232 | 1235 | "<table>\n",
|
1233 | 1236 | " <thead>\n",
|
1234 | 1237 | " <th>Align</th>\n",
|
1235 | 1238 | " <th>All Negative</th>\n",
|
1236 |
| - " <th>All Positive</th>\n", |
1237 | 1239 | " <th>Both Neg and Pos</th>\n",
|
| 1240 | + " <th>All Positive</th>\n", |
| 1241 | + " <th>Large Positive</th>\n", |
1238 | 1242 | " </thead>\n",
|
1239 | 1243 | " </tbody>\n",
|
1240 | 1244 | "\n",
|
1241 | 1245 | "\"\"\"\n",
|
1242 | 1246 | "\n",
|
1243 |
| - "aligns = ['left','zero','mid']\n", |
| 1247 | + "aligns = ['left', 'right', 'zero', 'mid', 'mean', 99]\n", |
1244 | 1248 | "for align in aligns:\n",
|
1245 | 1249 | " row = \"<tr><th>{}</th>\".format(align)\n",
|
1246 |
| - " for series in [test1,test2,test3]:\n", |
| 1250 | + " for series in [test1,test2,test3, test4]:\n", |
1247 | 1251 | " s = series.copy()\n",
|
1248 | 1252 | " s.name=''\n",
|
1249 |
| - " row += \"<td>{}</td>\".format(s.to_frame().style.bar(align=align, \n", |
| 1253 | + " row += \"<td>{}</td>\".format(s.to_frame().style.hide_index().bar(align=align, \n", |
1250 | 1254 | " color=['#d65f5f', '#5fba7d'], \n",
|
1251 | 1255 | " width=100).render()) #testn['width']\n",
|
1252 | 1256 | " row += '</tr>'\n",
|
|
0 commit comments