|
49 | 49 | "source": [
|
50 | 50 | "import pandas as pd\n",
|
51 | 51 | "import numpy as np\n",
|
| 52 | + "import matplotlib as mpl\n", |
52 | 53 | "\n",
|
53 | 54 | "df = pd.DataFrame([[38.0, 2.0, 18.0, 22.0, 21, np.nan],[19, 439, 6, 452, 226,232]], \n",
|
54 | 55 | " index=pd.Index(['Tumour (Positive)', 'Non-Tumour (Negative)'], name='Actual Label:'), \n",
|
|
1275 | 1276 | "cell_type": "markdown",
|
1276 | 1277 | "metadata": {},
|
1277 | 1278 | "source": [
|
1278 |
| - "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", |
| 1279 | + "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 or a matplotlib colormap.\n", |
1279 | 1280 | "\n",
|
1280 |
| - "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:" |
| 1281 | + "To showcase an example 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. We also use `text_gradient` to color the text the same as the bars using a matplotlib colormap (although in this case the visualization is probably better without this additional effect)." |
1281 | 1282 | ]
|
1282 | 1283 | },
|
1283 | 1284 | {
|
|
1286 | 1287 | "metadata": {},
|
1287 | 1288 | "outputs": [],
|
1288 | 1289 | "source": [
|
1289 |
| - "df2.style.bar(align=0, vmin=-2.5, vmax=2.5, color=['#d65f5f', '#5fba7d'], height=50,\n", |
1290 |
| - " width=60, props=\"width: 120px; border-right: 1px solid black;\").format('{:.3f}', na_rep=\"\")" |
| 1290 | + "df2.style.format('{:.3f}', na_rep=\"\")\\\n", |
| 1291 | + " .bar(align=0, vmin=-2.5, vmax=2.5, color=mpl.cm.get_cmap(\"bwr\"), height=50,\n", |
| 1292 | + " width=60, props=\"width: 120px; border-right: 1px solid black;\")\\\n", |
| 1293 | + " .text_gradient(cmap=\"bwr\", vmin=-2.5, vmax=2.5)" |
1291 | 1294 | ]
|
1292 | 1295 | },
|
1293 | 1296 | {
|
|
2031 | 2034 | "name": "python",
|
2032 | 2035 | "nbconvert_exporter": "python",
|
2033 | 2036 | "pygments_lexer": "ipython3",
|
2034 |
| - "version": "3.8.7" |
| 2037 | + "version": "3.8.6" |
2035 | 2038 | }
|
2036 | 2039 | },
|
2037 | 2040 | "nbformat": 4,
|
|
0 commit comments