Skip to content

Commit a7409d0

Browse files
committed
Add Box Plot and Heatmap rows to the comparison
Box plot shows hwy by class from mpg; heatmap shows diamonds counts by cut and clarity. seaborn.objects is skipped for both: 0.13 has no boxplot mark and no rect mark, and pandas has no heatmap.
1 parent d8ae81d commit a7409d0

3 files changed

Lines changed: 369 additions & 0 deletions

File tree

Examples.ipynb

Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,174 @@
698698
"sns.histplot(mpg, x='cty', binwidth=2);"
699699
]
700700
},
701+
{
702+
"cell_type": "markdown",
703+
"metadata": {},
704+
"source": [
705+
"#### Box Plot of a Continuous Value by Category"
706+
]
707+
},
708+
{
709+
"cell_type": "code",
710+
"execution_count": null,
711+
"metadata": {
712+
"tags": [
713+
"ex",
714+
"name:box-plot",
715+
"package:ggplot"
716+
]
717+
},
718+
"outputs": [],
719+
"source": [
720+
"%%R -w 10 -h 10 -u in\n",
721+
"ggplot(data=mpg) +\n",
722+
" aes(x=class, y=hwy) +\n",
723+
" geom_boxplot()"
724+
]
725+
},
726+
{
727+
"cell_type": "code",
728+
"execution_count": null,
729+
"metadata": {
730+
"tags": [
731+
"ex",
732+
"name:box-plot",
733+
"package:pandas"
734+
]
735+
},
736+
"outputs": [],
737+
"source": [
738+
"mpg.boxplot(column='hwy', by='class',\n",
739+
" rot=45);"
740+
]
741+
},
742+
{
743+
"cell_type": "code",
744+
"execution_count": null,
745+
"metadata": {
746+
"tags": [
747+
"ex",
748+
"name:box-plot",
749+
"package:plotnine"
750+
]
751+
},
752+
"outputs": [],
753+
"source": [
754+
"(ggplot(mpg) +\n",
755+
" aes(x=\"class\", y=\"hwy\") +\n",
756+
" geom_boxplot())"
757+
]
758+
},
759+
{
760+
"cell_type": "code",
761+
"execution_count": null,
762+
"metadata": {
763+
"tags": [
764+
"ex",
765+
"name:box-plot",
766+
"package:lets-plot"
767+
]
768+
},
769+
"outputs": [],
770+
"source": [
771+
"(lp.ggplot(mpg) +\n",
772+
" lp.aes(x=\"class\", y=\"hwy\") +\n",
773+
" lp.geom_boxplot())"
774+
]
775+
},
776+
{
777+
"cell_type": "code",
778+
"execution_count": null,
779+
"metadata": {
780+
"tags": [
781+
"ex",
782+
"name:box-plot",
783+
"package:plotly"
784+
]
785+
},
786+
"outputs": [],
787+
"source": [
788+
"px.box(\n",
789+
" mpg, x=\"class\", y=\"hwy\"\n",
790+
")"
791+
]
792+
},
793+
{
794+
"cell_type": "code",
795+
"execution_count": null,
796+
"metadata": {
797+
"tags": [
798+
"ex",
799+
"name:box-plot",
800+
"package:altair"
801+
]
802+
},
803+
"outputs": [],
804+
"source": [
805+
"(\n",
806+
" alt.Chart(mpg)\n",
807+
" .mark_boxplot()\n",
808+
" .encode(x=\"class\", y=\"hwy\")\n",
809+
" .properties(width=400)\n",
810+
")"
811+
]
812+
},
813+
{
814+
"cell_type": "code",
815+
"execution_count": null,
816+
"metadata": {
817+
"tags": [
818+
"ex",
819+
"name:box-plot",
820+
"package:hvplot"
821+
]
822+
},
823+
"outputs": [],
824+
"source": [
825+
"mpg.hvplot.box(y=\"hwy\", by=\"class\",\n",
826+
" rot=45)"
827+
]
828+
},
829+
{
830+
"cell_type": "code",
831+
"execution_count": null,
832+
"metadata": {
833+
"tags": [
834+
"ex",
835+
"name:box-plot",
836+
"package:matplotlib"
837+
]
838+
},
839+
"outputs": [],
840+
"source": [
841+
"\"\"\"`boxplot` takes a list of arrays, so the\n",
842+
"groups are split by hand.\n",
843+
"\"\"\"\n",
844+
"groups = mpg.groupby('class')['hwy']\n",
845+
"fig, ax = pyplot.subplots()\n",
846+
"ax.boxplot([v for _, v in groups],\n",
847+
" tick_labels=list(groups.groups))\n",
848+
"ax.set_xlabel('class')\n",
849+
"ax.set_ylabel('hwy')\n",
850+
"pyplot.xticks(rotation=45);"
851+
]
852+
},
853+
{
854+
"cell_type": "code",
855+
"execution_count": null,
856+
"metadata": {
857+
"tags": [
858+
"ex",
859+
"name:box-plot",
860+
"package:seaborn"
861+
]
862+
},
863+
"outputs": [],
864+
"source": [
865+
"ax = sns.boxplot(mpg, x='class', y='hwy')\n",
866+
"ax.tick_params(axis='x', rotation=45);"
867+
]
868+
},
701869
{
702870
"cell_type": "markdown",
703871
"metadata": {},
@@ -2855,6 +3023,184 @@
28553023
"source": [
28563024
"sns.lineplot(ts, x='date', y='value');"
28573025
]
3026+
},
3027+
{
3028+
"cell_type": "markdown",
3029+
"metadata": {},
3030+
"source": [
3031+
"#### Heatmap of Counts by Two Categories"
3032+
]
3033+
},
3034+
{
3035+
"cell_type": "code",
3036+
"execution_count": null,
3037+
"metadata": {
3038+
"tags": [
3039+
"ex",
3040+
"name:heatmap",
3041+
"package:ggplot"
3042+
]
3043+
},
3044+
"outputs": [],
3045+
"source": [
3046+
"%%R -w 10 -h 10 -u in\n",
3047+
"ggplot(data=diamonds) +\n",
3048+
" aes(x=cut, y=clarity) +\n",
3049+
" geom_bin2d()"
3050+
]
3051+
},
3052+
{
3053+
"cell_type": "code",
3054+
"execution_count": null,
3055+
"metadata": {
3056+
"tags": [
3057+
"ex",
3058+
"name:heatmap",
3059+
"package:plotnine"
3060+
]
3061+
},
3062+
"outputs": [],
3063+
"source": [
3064+
"(ggplot(diamonds) +\n",
3065+
" aes(x=\"cut\", y=\"clarity\") +\n",
3066+
" geom_bin2d())"
3067+
]
3068+
},
3069+
{
3070+
"cell_type": "code",
3071+
"execution_count": null,
3072+
"metadata": {
3073+
"tags": [
3074+
"ex",
3075+
"name:heatmap",
3076+
"package:lets-plot"
3077+
]
3078+
},
3079+
"outputs": [],
3080+
"source": [
3081+
"(lp.ggplot(diamonds) +\n",
3082+
" lp.aes(x=\"cut\", y=\"clarity\") +\n",
3083+
" lp.geom_bin2d())"
3084+
]
3085+
},
3086+
{
3087+
"cell_type": "code",
3088+
"execution_count": null,
3089+
"metadata": {
3090+
"tags": [
3091+
"ex",
3092+
"name:heatmap",
3093+
"package:plotly"
3094+
]
3095+
},
3096+
"outputs": [],
3097+
"source": [
3098+
"px.density_heatmap(\n",
3099+
" diamonds, x=\"cut\", y=\"clarity\"\n",
3100+
")"
3101+
]
3102+
},
3103+
{
3104+
"cell_type": "code",
3105+
"execution_count": null,
3106+
"metadata": {
3107+
"tags": [
3108+
"ex",
3109+
"name:heatmap",
3110+
"package:altair"
3111+
]
3112+
},
3113+
"outputs": [],
3114+
"source": [
3115+
"alt.data_transformers.disable_max_rows()\n",
3116+
"(\n",
3117+
" alt.Chart(diamonds)\n",
3118+
" .mark_rect()\n",
3119+
" .encode(\n",
3120+
" x=\"cut\", y=\"clarity\",\n",
3121+
" color=\"count()\",\n",
3122+
" )\n",
3123+
" .properties(width=400, height=400)\n",
3124+
")"
3125+
]
3126+
},
3127+
{
3128+
"cell_type": "code",
3129+
"execution_count": null,
3130+
"metadata": {
3131+
"tags": [
3132+
"ex",
3133+
"name:heatmap",
3134+
"package:hvplot"
3135+
]
3136+
},
3137+
"outputs": [],
3138+
"source": [
3139+
"\"\"\"hvPlot needs the counts up front; `C` names\n",
3140+
"the column that colors each tile.\n",
3141+
"\"\"\"\n",
3142+
"(diamonds\n",
3143+
" .groupby([\"cut\", \"clarity\"])\n",
3144+
" .size()\n",
3145+
" .reset_index(name=\"count\")\n",
3146+
" .hvplot.heatmap(x=\"cut\", y=\"clarity\",\n",
3147+
" C=\"count\", rot=45))"
3148+
]
3149+
},
3150+
{
3151+
"cell_type": "code",
3152+
"execution_count": null,
3153+
"metadata": {
3154+
"tags": [
3155+
"ex",
3156+
"name:heatmap",
3157+
"package:matplotlib"
3158+
]
3159+
},
3160+
"outputs": [],
3161+
"source": [
3162+
"\"\"\"Matplotlib has no heatmap function, so the\n",
3163+
"counts are pivoted and drawn with `pcolormesh`.\n",
3164+
"\"\"\"\n",
3165+
"counts = (diamonds\n",
3166+
" .groupby(['clarity', 'cut'])\n",
3167+
" .size()\n",
3168+
" .unstack())\n",
3169+
"fig, ax = pyplot.subplots()\n",
3170+
"mesh = ax.pcolormesh(counts.values)\n",
3171+
"ax.set_xticks(\n",
3172+
" np.arange(len(counts.columns)) + .5,\n",
3173+
" counts.columns, rotation=45)\n",
3174+
"ax.set_yticks(\n",
3175+
" np.arange(len(counts.index)) + .5,\n",
3176+
" counts.index)\n",
3177+
"ax.set_xlabel('cut')\n",
3178+
"ax.set_ylabel('clarity')\n",
3179+
"fig.colorbar(mesh, label='count');"
3180+
]
3181+
},
3182+
{
3183+
"cell_type": "code",
3184+
"execution_count": null,
3185+
"metadata": {
3186+
"tags": [
3187+
"ex",
3188+
"name:heatmap",
3189+
"package:seaborn"
3190+
]
3191+
},
3192+
"outputs": [],
3193+
"source": [
3194+
"\"\"\"`heatmap` colors a matrix, so the counts are\n",
3195+
"pivoted into one first.\n",
3196+
"\"\"\"\n",
3197+
"counts = (diamonds\n",
3198+
" .groupby(['clarity', 'cut'])\n",
3199+
" .size()\n",
3200+
" .unstack())\n",
3201+
"sns.heatmap(counts,\n",
3202+
" cbar_kws=dict(label='count'));"
3203+
]
28583204
}
28593205
],
28603206
"metadata": {

render.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
names = {
3333
"bar-counts": "Bar Chart",
3434
"simple-histogram": "Histogram",
35+
"box-plot": "Box Plot",
3536
"scatter-plot": "Scatter Plot",
3637
"timeseries": "Time Series",
3738
"scatter-plot-with-colors": "Scatter Plot with Faceted with Color",
@@ -43,6 +44,7 @@
4344
"stacked-bar-chart": "Stacked Bar Chart",
4445
"dodged-bar-chart": "Dodged Bar Chart",
4546
"stacked-kde": "Stacked KDE Plot",
47+
"heatmap": "Heatmap",
4648
}
4749

4850
with open("INTRO.md", "r") as f:

0 commit comments

Comments
 (0)