It has been quite sometime since I used seaborn library and was finding it difficult to remember some basic functions from the package. Took some time out and did a deliberate practice session for a few hours

What did I relearn ?

  • seaborn works with matplotlib and updates the defaults to better defaults
  • seaborn uses a lot of default matplotlib functionality
  • seaborn works with pandas data frames. You can pass dataframes and let seaborn use the relevant variable
  • kdeplot= to plot density estimates
  • distplot has been deprecated
  • There are three distribution plot options available
    • histplot
    • ecdfplot
    • distplot
  • There are two types of plots - figure level plots and axes level plots
  • Figure level plots are relplot, displot and catplot
  • ecdfplot
    • central tendencies and summary stats cannot be seen
    • No binning
    • returns a matplotlib object and you can then manipulate the same
  • boxplot
    • a plot that shows the median, percentiles, the outliers
    • find the median, concentrate on the lower half and draw a median, concentrate on the upper half and draw a line. The median and the percentile points represent the box.
    • Find the IQR and stretch the whiskers by 1.5 times and show the whiskers
    • The points that lie outside of whiskers are the outliers
    • Strictly the whiskers are based on the actual values in the data
    • There are many more options for a user to customize the boxplot than what is mentioned in the seaborn=
  • violinplot
    • It is a categorical distribution plot
    • There are several similarities with box plot. You can see the median and percentiles
    • There are no outliers in the violin plot
    • violinplot is symmetric and hence there is an additional info
    • You take a KDE plot and create a symmetric version of kde plot and show the plot as violin
  • swarmplot
    • The name comes from the fact that the plots look like a swarm of bees
    • There is a dot for every single data point
    • this plot doesn’t scale well if you have lots of data
    • It gets you a sense of distribution of data
    • inherits from matplotlib’s scatter plot
  • stripplot
    • categorical scatterplot
    • Similar to swarmplot
    • swarmplot are arranged as separate and hence the width of the swarmplot can be used to infer the distribution of data
    • stripplot can be used in cases when there is large data where swarmplot might not make sense
    • use jitter to separate the points in the plot that take identical values
  • scatterplot
    • One of the most popular plots
    • There are a ton of options to add semantic elements to a simple x y plot.
    • One can overlay additional dimensionality on an x y plot using hue, size, style
  • lineplot
    • used to draw a line between two variables connecting means and bootstrapped confidence intervals
    • One can also disable the plotting of confidence intervals
    • One can also choose various estimators to plot instead of the standard average value
  • regplot
    • Used to plot a regression line and relevant confidence intervals for a set of data points
  • heatmap
    • Very useful for showing the variation across a matrix of values
    • parameters to control the label on both axis, annotation, font size of the annotation, the color palette that can be used and whole host of options
  • FacetGrid
    • One can use the variables in the dataframe and draw conditional plots. Based on the specified rows and columns in the argument, separate plots are drawn for each combination of row and column
  • displot
    • stands for distribution plot
    • distplot is deprecated
    • one distribution plot to rule them all
    • histplot, kdeplot, ecdfplot and rugplot comes along
    • It is a figure level visual
    • bivariate relationship can be plotted and appears similar to heatmap
    • FacetGrid can be leveraged
  • barplot
    • a categorical vs numerical variable plot.
    • For the data grouped by the categorical variable, the plot shows the mean of the numerical variable
    • There are also confidence intervals that are displayed. These CIs are computed via bootstrapping
  • countplot
    • count up the number of observations per category
    • histogram for categorical data
    • Overlay the count with another categorical variable with hue
    • different from barplot as the barplot is used to plot statistical summary of data grouped by a specific variable
    • more than 170 palettes to pick from
    • pass arguments to matplotlib
  • pairplot
    • This plot is applicable to all the numerical variables in a dataframe. Univariate and Bivariate relationships are all drawn at once on the plot.
    • The plots on the diagonal are either histogram or kde plot
    • The plots on the off-diagonal are either reg plot or scatter plot or kde plot
    • One can ofcourse use a categorical variable to visualize subplots for each category using color
    • The more I think about these plot, the more I think these plots are usually finished plots that can be used to communicate all relationships at once. One would obviously use univariate plots to understand each variable and probably a reg or scatter or kde plot to understand the way things move. It is unlikely that one would want to go for a pairplot all at once
  • jointplot
    • This plot is similar to pairplot in the sense that it plots univariate and join plots. Main difference is that this plot is for only two variables whereas pairplot can be used for many variables, i.e. there are more cells in the matrix in pairplot whereas there is only one cell with margins on the top. So, one can think of jointplot as pairplot with four cells.
    • This means that if you understand the various arguments that one uses in pairplot, the jointplot looks very similar. Instead of diag_kws, one has to use marginal_kws. Instead of using plot_kws, one needs to use joint_kws

Sample code used to practice

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import matplotlib

cars = sns.load_dataset("mpg").dropna()
sns.__version__
matplotlib.__version__

sns.set()
x = np.arange(10)
plt.plot(x, x)
plt.show()
cars.head(10)

sns.kdeplot(data=cars, x="mpg")
plt.show()
sns.kdeplot(data=cars, x="horsepower")
plt.show()
sns.kdeplot(cars.mpg, fill=True)
plt.show()


sns.kdeplot(cars.horsepower, fill=True, bw_adjust=0.2)
plt.show()
sns.kdeplot(cars.horsepower, fill=True, bw_adjust=0.5)
plt.show()
sns.kdeplot(cars.horsepower, fill=True, bw_adjust=2)
plt.show()

sns.kdeplot(data=cars, x="horsepower", y="mpg")
plt.show()

sns.kdeplot(data=cars, x="horsepower", y="mpg", fill=True)
plt.show()

sns.kdeplot(data=cars, x="horsepower", y="mpg", fill=True, cbar=True)
plt.show()

temp = cars[cars.cylinders.isin([4, 8])].copy()
sns.kdeplot(data=temp, x="horsepower", y="mpg", fill=True, cbar=True, hue="cylinders")
plt.show()

sns.kdeplot(data=temp, x="horsepower", y="mpg", fill=True, cbar=False, hue="cylinders")
plt.show()

import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = sns.load_dataset("penguins")
df = df.dropna()

df.columns

sns.histplot(data=df, x="bill_length_mm", kde=True)
plt.show()

sns.histplot(data=df, x="bill_length_mm", kde=True, bins=20)
plt.show()

sns.histplot(data=df, x="bill_length_mm", kde=True, bins=[20, 30, 40])
plt.show()

sns.histplot(data=df, x="bill_length_mm", kde=True, binwidth=2)
plt.show()

sns.histplot(data=df, x="bill_length_mm", kde=True, binwidth=2, binrange=[30, 40])
plt.show()

sns.histplot(
    data=df, x="bill_length_mm", kde=True, binwidth=2, binrange=[30, 80], stat="count"
)
plt.show()

sns.histplot(
    data=df, x="bill_length_mm", kde=True, binwidth=2, binrange=[30, 80], stat="density"
)
plt.show()

sns.histplot(
    data=df, x="bill_length_mm", kde=True, binwidth=2, binrange=[30, 80], stat="density"
)
plt.show()

sns.histplot(data=df, x="bill_length_mm", kde=True, stat="probability")
plt.show()

sns.histplot(data=df, x="bill_length_mm", kde=True, cumulative=True, stat="probability")
plt.show()

sns.histplot(data=df, x="bill_length_mm", kde=True, stat="percent")
plt.show()

sns.histplot(data=df, x="bill_length_mm", hue="species", stat="percent")
plt.show()

sns.histplot(data=df, x="bill_length_mm", hue="species", element="step", stat="percent")
plt.show()

sns.histplot(
    data=df, x="bill_length_mm", hue="species", multiple="stack", stat="percent"
)
plt.show()

sns.histplot(
    data=df, x="bill_length_mm", hue="species", multiple="fill", stat="percent"
)
plt.show()

df.columns
sns.set_style("white")
sns.histplot(data=df, x="bill_length_mm", y="bill_depth_mm", cbar=True)
plt.show()

sns.histplot(data=df, x="bill_length_mm", y="bill_depth_mm", hue="species", legend=True)
plt.show()

sns.histplot(x="species", hue="sex", multiple="dodge", data=df, shrink=0.8)
plt.show()

sns.histplot(x="species", hue="sex", multiple="dodge", data=df, shrink=0.8)
plt.show()

sns.histplot(
    x="species", hue="sex", multiple="dodge", data=df, shrink=0.8, palette="bone"
)
plt.show()

sns.histplot(
    x="species", hue="sex", multiple="dodge", data=df, shrink=0.8, color="indigo"
)
plt.show()


sns.histplot(x="species", hue="sex", multiple="dodge", data=df, shrink=0.8, fill=False)
plt.show()

sns.ecdfplot(df.bill_depth_mm)
plt.show()

sns.ecdfplot(data=df, x="bill_depth_mm")
plt.axvline(16, c="black")
plt.show()

sns.ecdfplot(data=df, y="bill_depth_mm")
plt.show()

sns.ecdfplot(data=df, y="bill_depth_mm")
plt.axvline(0.5)
plt.show()

df = sns.load_dataset("tips")

sns.ecdfplot(data=df, x="tip", hue="time")
plt.show()

sns.ecdfplot(data=df, x="tip", hue="day")
plt.show()

sns.ecdfplot(data=df, x="tip", hue="day", stat="count")
plt.show()

sns.ecdfplot(data=df, x="tip", hue="day", stat="count", complementary=True)
plt.show()

sns.ecdfplot(data=df, x="tip", stat="count", complementary=True)
plt.show()

sns.ecdfplot(data=df, x="tip", weights="tip")
plt.axhline(0.5, c="black")
plt.show()

sns.ecdfplot(data=df, x="tip", hue="day")
plt.show()

sns.ecdfplot(data=df, x="tip", hue="day", palette="summer", lw=2)
plt.show()

p = sns.ecdfplot(data=df, x="tip", hue="day", palette="summer", lw=2)
type(p)
p.legend(["Thursday", "Friday", "Saturday", "Sunday"])
plt.show()

cars = sns.load_dataset("mpg").dropna()
cars.columns
sns.set_style("whitegrid")
cars.cylinders.value_counts()
cars = cars[cars.cylinders.isin([4, 6, 8])]
sns.boxplot(data=cars, x="mpg")
plt.show()
cars.mpg.describe()
sns.boxplot(data=cars, x="origin", y="mpg")
plt.show()


sns.boxplot(data=cars, x="origin", y="mpg", hue="cylinders")
plt.show()
cars.model_year
cars.model_year.describe()
cars = cars.assign(newer_model=np.where(cars.model_year > 76, True, False))

sns.boxplot(data=cars, x="origin", y="mpg", hue="newer_model")
plt.show()

sns.boxplot(data=cars, x="origin", y="mpg")
plt.show()


sns.boxplot(data=cars, x="origin", y="mpg")
plt.show()

sns.boxplot(data=cars, x="origin", y="mpg", order=["japan", "usa", "europe"])
plt.show()

sns.boxplot(
    data=cars,
    x="origin",
    y="mpg",
    hue="newer_model",
    order=["japan", "usa", "europe"],
    hue_order=[False, True],
)
plt.show()

sns.boxplot(
    data=cars,
    x="origin",
    y="mpg",
    hue="newer_model",
    order=["japan", "usa", "europe"],
    hue_order=[True, False],
)
plt.show()

sns.boxplot(
    data=cars,
    x="origin",
    y="mpg",
    hue="newer_model",
    order=["japan", "usa", "europe"],
    hue_order=[True, False],
    width=1,
    linewidth=2.5,
)
plt.show()

sns.boxplot(
    data=cars,
    x="origin",
    y="mpg",
    hue="newer_model",
    order=["japan", "usa", "europe"],
    hue_order=[True, False],
    width=1,
    linewidth=2.5,
    whis=3,
)
plt.show()

sns.boxplot(
    data=cars,
    x="origin",
    y="mpg",
    hue="newer_model",
    order=["japan", "usa", "europe"],
    hue_order=[True, False],
    width=0.5,
    linewidth=1,
    whis=1,
    fliersize=3,
    showcaps=False,
)
plt.show()

sns.violinplot(data=cars, x="displacement")
plt.show()

sns.violinplot(data=cars, x="cylinders", y="displacement")
plt.show()

sns.violinplot(data=cars, x="cylinders", y="displacement", hue="origin")
plt.show()
temp = cars[cars.origin.isin(["japan", "europe"])]

sns.violinplot(data=temp, x="cylinders", y="displacement", hue="origin", split=True)
plt.show()

sns.violinplot(
    data=temp,
    x="cylinders",
    y="displacement",
    hue="origin",
    split=True,
    inner="quartiles",
    scale="count",
)
plt.show()

sns.violinplot(
    data=temp,
    x="cylinders",
    y="displacement",
    hue="origin",
    split=True,
    inner="quartiles",
    scale="count",
    scale_hue=False,
)
plt.show()

sns.violinplot(data=temp, x="origin", y="displacement", order=["europe", "japan"])
plt.show()

sns.violinplot(
    data=temp, x="origin", y="displacement", order=["europe", "japan"], linewidth=3
)
plt.show()

sns.violinplot(
    data=temp,
    x="origin",
    y="displacement",
    order=["europe", "japan"],
    linewidth=3,
    bw=0.2,
)
plt.show()


sns.swarmplot(data=cars, x="origin", y="displacement")
plt.show()

sns.swarmplot(data=cars, x="origin", y="horsepower", hue="cylinders", dodge=True)
plt.show()


usa = cars[cars.origin == "usa"]

sns.boxplot(data=usa, x="cylinders", y="horsepower", whis=np.inf)
sns.swarmplot(data=usa, x="cylinders", y="horsepower", color="black", alpha=0.2)
plt.show()


sns.violinplot(data=usa, x="cylinders", y="horsepower", whis=np.inf, scale="width")
sns.swarmplot(data=usa, x="cylinders", y="horsepower", color="black", alpha=0.2)
plt.show()


sns.violinplot(data=usa, x="cylinders", y="horsepower", whis=np.inf, scale="width")

sns.swarmplot(data=usa, x="cylinders", y="horsepower", color="black", alpha=0.2, size=4)
plt.show()


sns.swarmplot(data=usa, x="cylinders", y="horsepower", color="black", alpha=0.2, size=4)
plt.show()


sns.swarmplot(
    data=usa,
    x="cylinders",
    y="horsepower",
    color="black",
    alpha=0.2,
    size=4,
    marker="*",
)
plt.show()

np.random.np.arange(10)

sns.stripplot(data=cars, x="weight")
plt.show()

sns.stripplot(data=cars, x="weight", y="origin", hue="origin")
plt.show()

sns.stripplot(data=cars, x="weight", y="origin", hue="cylinders")
plt.show()

sns.stripplot(data=cars, x="weight", y="origin", hue="cylinders", dodge=True)
plt.show()

sns.stripplot(data=cars, y="weight", x="origin", hue="cylinders", dodge=True)
plt.show()


sns.stripplot(data=cars, y="weight", x="origin", hue="cylinders", jitter=False)
plt.show()

sns.stripplot(data=cars, y="weight", x="origin", hue="cylinders", jitter=0.04)
plt.show()

sns.stripplot(
    data=cars, y="weight", x="origin", hue="cylinders", jitter=0.04, alpha=0.4
)
plt.show()

sns.stripplot(
    data=cars, y="weight", x="origin", hue="cylinders", jitter=0.04, alpha=0.3, size=4
)
plt.show()

sns.stripplot(
    data=cars,
    y="weight",
    x="origin",
    hue="cylinders",
    jitter=0.04,
    alpha=0.3,
    size=4,
    linewidth=1,
)
plt.show()


sns.stripplot(
    data=cars,
    x="weight",
    y="origin",
    hue="cylinders",
    jitter=0.04,
    alpha=0.3,
    size=4,
    linewidth=1,
)
plt.show()

cars.columns
cars.head(1).T
sns.stripplot(
    data=cars, x="weight", y="origin",
)
plt.show()

help(sns.stripplot)

diamonds = sns.load_dataset("diamonds")
diamonds[diamonds.cut.isin(["Premium", "Good"]) & diamonds.color.isin(["D", "F", "J"])]
cars

sns.scatterplot(data=cars, x="cylinders", y="weight", color="purple", hue="newer_model")
plt.show()

sns.scatterplot(
    data=cars, x="cylinders", y="weight", color=["purple", "pink"], hue="newer_model"
)
plt.show()


sns.scatterplot(data=cars, x="cylinders", y="weight", color="#ff028d")
plt.show()

import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

sns.set_style("whitegrid")
df = pd.read_csv("dataset.csv", parse_dates=[3])
df.rename(
    columns={"SystemCodeNumber": "Location", "LastUpdated": "Timestamp"}, inplace=True
)

df = df.assign(Day=df.Timestamp.dt.date)
df = df.assign(Month=df.Timestamp.dt.month)
df = df.assign(Hour=df.Timestamp.dt.hour)

park = df[df.Location.isin(["Broad Street", "NIA South"])]
park.head()

blue, orange, green, red = sns.color_palette()[:4]
sns.set_style("white")
plt.rc("xtick", labelsize=14)
plt.rc("ytick", labelsize=14)
plt.rc("date.autoformatter", days="%b %Y")
import datetime

months = [
    datetime.datetime(2016, 10, 1),
    datetime.datetime(2016, 11, 1),
    datetime.datetime(2016, 12, 1),
]

plt.figure(figsize=(10, 6))
sns.lineplot(data=park, x="Day", y="Occupancy")
plt.xticks(months)
plt.yticks([])
plt.ylim(0, 570)
sns.despine(left=True)
plt.xlabel("")
plt.ylabel("")
plt.tight_layout()
plt.show()

plt.figure(figsize=(10, 6))
sns.lineplot(data=park, x="Day", y="Occupancy")
plt.xticks(months)
plt.yticks([])
plt.ylim(0, 570)
sns.despine(right=True, left=True)
plt.xlabel("")
plt.ylabel("")
plt.tight_layout()
plt.show()

plt.figure(figsize=(12, 8))
sns.lineplot(
    data=park, x="Day", y="Occupancy", hue="Location", palette=["gray", "purple"]
)
plt.xticks(months)
plt.yticks([])
plt.ylim(0, 570)
plt.xlabel("")
plt.ylabel("")
plt.legend([], frameon=False)
plt.tight_layout()
plt.show()


plt.rc("date.autoformatter", day="%b 1st")
plt.figure(figsize=(6, 4))
sns.lineplot(data=park, x="Day", y="Occupancy")
plt.xticks(months)
plt.yticks([])
plt.xlim(pd.datetime(2016, 10, 30), pd.datetime(2016, 11, 6))
plt.ylim(0, 600)
plt.xlabel("")
plt.ylabel("")
plt.show()

plt.rc("date.autoformatter", day="%b 1st")
plt.figure(figsize=(6, 4))
sns.lineplot(data=park, x="Day", y="Occupancy", ci=None)
plt.xticks(months)
plt.yticks([])
plt.xlim(pd.datetime(2016, 10, 30), pd.datetime(2016, 11, 6))
plt.ylim(0, 600)
plt.xlabel("")
plt.ylabel("")
plt.show()

sns.set_style("dark")
months = [
    datetime.datetime(2016, 10, 1),
    datetime.datetime(2016, 11, 1),
    datetime.datetime(2016, 12, 1),
]
plt.rc("date.autoformatter", day="%b %Y")
sns.lineplot(data=park, x="Day", y="Occupancy")
plt.show()


sns.lineplot(data=park, x="Hour", y="Occupancy")
plt.show()

sns.lineplot(x="Hour", y="Occupancy", data=park, n_boot=10)
plt.show()
sns.lineplot(x="Hour", y="Occupancy", data=park, n_boot=100, ci=95)
plt.show()
sns.lineplot(x="Hour", y="Occupancy", data=park, n_boot=100, ci=68)
plt.show()
sns.lineplot(x="Hour", y="Occupancy", data=park, n_boot=100, ci=None)
plt.show()

sns.lineplot(x="Hour", y="Occupancy", data=park, n_boot=100, ci=None, estimator="sum")
plt.show()

import matplotlib.pyplot as plt

xs = np.arange(-(9), (9), 0.01)
ys = -np.square(xs)
cols = ["red", "orange", "yellow", "green", "blue", "purple", "pink"]
cols_labels = [i.upper() for i in cols]

for i in range(7):
    sns.lineplot(x=xs, y=ys - 10 * (i - 1), c=cols[i], label=cols_labels[i])
plt.legend()
plt.show()

cols = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
cols_labels = [i.upper() for i in cols]

for i in range(7):
    sns.lineplot(x=xs, y=ys - 10 * (i - 1), c=cols[i], label=cols_labels[i])
plt.legend()
plt.show()


cols = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
cols_labels = [i.upper() for i in cols]

for i in range(7):
    sns.lineplot(
        x=xs, y=ys - 10 * (i - 1), color=cols[i], label=cols_labels[i], lw=10, alpha=0.3
    )
plt.legend()
plt.show()


diamonds = sns.load_dataset("diamonds")
diamonds.shape
diamonds = (
    diamonds[
        diamonds.cut.isin(["Premium", "Good"]) & diamonds.color.isin(["D", "F", "J"])
    ]
    .sample(n=100, random_state=22)
    .copy()
)
diamonds.cut.value_counts()
diamonds.cut = diamonds.cut.astype("str")
sns.set_style("white")
plt.rc("xtick", labelsize=14)
plt.rc("ytick", labelsize=14)


diamonds.columns

sns.scatterplot(data=diamonds, x="carat", y="price")
plt.show()

sns.scatterplot(data=diamonds, x="carat", y="price", hue="cut")
plt.show()

sns.scatterplot(data=diamonds, x="carat", y="price", hue="cut", palette=["red", "blue"])
plt.show()

sns.scatterplot(
    data=diamonds,
    x="carat",
    y="price",
    hue="cut",
    palette=["red", "blue"],
    hue_order=["Good", "Premium"],
)
plt.show()

sns.scatterplot(
    data=diamonds,
    x="carat",
    y="price",
    hue="cut",
    palette=["red", "blue"],
    hue_order=["Good", "Premium"],
    s=2,
)
plt.show()

sns.scatterplot(data=diamonds, x="carat", y="price", size="cut", sizes=[10, 50])
plt.show()

sns.scatterplot(
    data=diamonds, x="carat", y="price", size="cut", sizes=[10, 50], marker="*"
)
plt.show()

import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

diamonds = sns.load_dataset("diamonds")
diamonds.shape

diamonds = diamonds.sample(n=200, random_state=1200)
plt.rc("xtick", labelsize=12)
plt.rc("ytick", labelsize=12)


temp = sns.regplot(data=diamonds, x="carat", y="price")
temp.axes.set_title("test plot", fontsize=20)
temp.axes.set_xlabel("x", fontsize=14)
temp.axes.set_ylabel("y", fontsize=14)
plt.show()


temp = sns.regplot(data=diamonds, x="carat", y="price", fit_reg=False)
temp.axes.set_title("test plot", fontsize=20)
temp.axes.set_xlabel("x", fontsize=14)
temp.axes.set_ylabel("y", fontsize=14)
plt.show()


temp = sns.regplot(data=diamonds, x="carat", y="price", scatter=False)
temp.axes.set_title("test plot", fontsize=20)
temp.axes.set_xlabel("x", fontsize=14)
temp.axes.set_ylabel("y", fontsize=14)
plt.show()

temp = sns.regplot(data=diamonds, x="carat", y="price", ci=None)
temp.axes.set_title("test plot", fontsize=20)
temp.axes.set_xlabel("x", fontsize=14)
temp.axes.set_ylabel("y", fontsize=14)
plt.show()


cut_map = {
    'Fair':1,
    'Good':2,
    'Very Good':3,
    'Premium':4,
    'Ideal':5
}
diamonds = diamonds.assign(cut_value =diamonds.cut.map(cut_map))

diamonds.cut_value = diamonds.cut_value.astype('int')
.value_counts()

diamonds.cut_value.as_ordered()
sns.regplot(x='cut_value', y = 'price', data = diamonds, x_jitter=0.1)
plt.show()


sns.regplot(x='cut_value', y = 'price', data = diamonds, x_jitter=0.1, x_estimator=np.mean)
plt.show()


sns.regplot(x='carat', y = 'price', data = diamonds, order= 3)
plt.show()

sns.regplot(x='carat', y = 'price', data = diamonds, robust=True)
plt.show()


sns.regplot(x='carat', y = 'price', data = diamonds, robust=True,
            scatter_kws = {'s':100, 'alpha':0.5, 'color':'lightgray'})
plt.show()


sns.regplot(x='carat', y = 'price', data = diamonds,
            scatter_kws = {'s':100, 'alpha':0.5, 'color':'lightgray'})
plt.show()


sns.regplot(x='carat', y = 'price', data = diamonds,
            ci=None,
            line_kws = {'lw':4, 'color':'black', 'linestyle':'-.'})
plt.show()


temp = diamonds[diamonds.color.isin(['E','J'])].copy()
temp.color = temp.color.astype('str')

p = sns.lmplot(x ='carat', y = 'price', data = temp,
               hue='color', order =2, palette=['green','orange'])
p._legend.remove()
plt.legend(fontsize=16)
plt.show()

sns.jointplot(x ='carat', y = 'price', data = diamonds,
             kind = 'reg', color = 'purple')
plt.show()

sns.pairplot( data = diamonds[['carat','depth','price']],
             kind = 'reg')
plt.show()

import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

sns.set_theme("")
vals = np.random.choice(np.arange(100), 20).reshape(4, -1)
df = pd.DataFrame(vals)
df.index = "A B C D".split()
df.columns = "Mon Tue Wed Thu Fri".split()

sns.heatmap(
    df, cbar=True, annot=True,
)
plt.show()

help(sns.heatmap)
sns.heatmap(
    df,
    cbar=True,
    annot=True,
    vmin=0,
    square=True,
    annot_kws={"fontsize": 14, "fontweight": "bold", "color": "black"},
)
plt.tick_params(
    which="both",
    bottom=False,
    top=False,
    right=False,
    left=False,
    labelbottom=False,
    labeltop=True,
)
plt.tight_layout()
plt.show()


sns.heatmap(
    df,
    cbar=True,
    annot=True,
    vmin=0,
    square=True,
    annot_kws={"fontsize": 14, "fontweight": "bold", "color": "black"},
    linewidth=1,
    linecolor="gray",
)
plt.tight_layout()
plt.show()


sns.heatmap(
    df,
    cbar=True,
    annot=True,
    vmin=0,
    square=True,
    annot_kws={"fontsize": 14, "fontweight": "bold", "color": "black"},
    linewidth=1,
    linecolor="lightgray",
)
plt.tight_layout()
plt.show()

sns.heatmap(
    df,
    cbar=True,
    annot=True,
    vmin=0,
    square=True,
    annot_kws={"fontsize": 14, "fontweight": "bold", "color": "black"},
    linewidth=1,
    linecolor="lightgray",
    cmap="Blues",
)
plt.tight_layout()
plt.show()


sns.heatmap(
    df,
    cbar=True,
    annot=True,
    vmin=0,
    square=True,
    fmt=".0f",
    annot_kws={"fontsize": 14, "fontweight": "bold", "color": "black"},
    linewidth=1,
    linecolor="lightgray",
    cmap="Blues",
)
plt.tight_layout()
plt.show()
df

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

sns.set_style("white")

penguins = sns.load_dataset("penguins")
pen_ex = penguins[penguins.species.isin(["Adelie", "Chinstrap"])]
pen_ex.body_mass_g.describe()

g = sns.FacetGrid(data=pen_ex, row="sex", col="species", aspect=1.75)
g.map_dataframe(sns.histplot, x="body_mass_g", binwidth=200, color="purple")
g.set_titles(row_template="{row_name}", col_template="{col_name} Penguins")
g.set_axis_labels("Body Mass(g)", "Count")
plt.tight_layout()
plt.rc("xtick", labelsize=10)
plt.rc("ytick", labelsize=10)
plt.rc("axes", labelsize=15)
plt.show()


g = sns.FacetGrid(data=penguins, columns="island", aspect=1.75)
g.map_dataframe(sns.histplot, x="body_mass_g", binwidth=200, color="purple")
g.set_titles(row_template="{row_name}", col_template="{col_name} Penguins")
g.set_axis_labels("Body Mass(g)", "Count")
plt.tight_layout()
plt.rc("xtick", labelsize=10)
plt.rc("ytick", labelsize=10)
plt.rc("axes", labelsize=15)
plt.show()

penguins.columns
g = sns.FacetGrid(data=penguins, col="island", hue="species")
g.map_dataframe(sns.scatterplot, x="bill_depth_mm", y="bill_length_mm")
g.add_legend()
plt.show()


g = sns.FacetGrid(data=penguins, col="island", hue="species", palette="prism")
g.map_dataframe(sns.scatterplot, x="bill_depth_mm", y="bill_length_mm")
g.add_legend()
plt.show()


cars = sns.load_dataset("mpg").dropna()
sns.displot(data=cars, x="weight", kde=True)
plt.show()

sns.displot(data=cars, x="weight", kind="kde")
plt.show()

sns.displot(data=cars, x="weight", kind="ecdf", rug=True)
plt.show()

sns.displot(data=cars, x="weight", kind="hist", rug=True, hue="origin")
plt.show()

sns.displot(data=cars, x="weight", kind="kde", rug=True, hue="origin")
plt.show()

sns.displot(data=cars, x="weight", y="horsepower")
plt.show()

sns.displot(data=cars, x="weight", y="horsepower", kind="kde")
plt.show()

sns.displot(data=cars, x="weight", y="horsepower", kind="kde", rug=True)
plt.show()

sns.displot(data=cars, x="weight", hue="origin", col="origin")
plt.show()

g = sns.FacetGrid(data=cars, col="origin")
g.map_dataframe(sns.histplot, x="weight")
plt.show()

sns.displot(data=cars, x="weight", hue="origin", col="origin", kind="kde", rug=True)
plt.show()

sns.displot(data=cars, x="weight", col="origin", row="cylinders")
plt.show()

sns.displot(data=cars, x="weight", hue="origin", col="origin", palette="bone")
plt.show()

sns.displot(data=cars, x="weight", hue="origin", col="origin", palette="bone", aspect=1)
plt.show()


sns.displot(
    data=cars, x="weight", col="origin", aspect=1, rug=True, rug_kws={"height": 0.1}
)
plt.show()

g = sns.displot(
    data=cars, x="weight", hue="origin", col="origin", palette="bone", aspect=1
)
g.axes_dict.items()
plt.show()

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

sns.set_style("white")
df = sns.load_dataset("tips")
sns.regplot(x="total_bill", y="tip", data=df)
plt.show()

sns.lmplot(x="total_bill", y="tip", data=df)
plt.show()

sns.lmplot(y="size", x="tip", data=df)
plt.show()

sns.lmplot(x="size", y="tip", data=df)
plt.show()
anscombe = sns.load_dataset("anscombe")
sns.lmplot(
    x="x",
    y="y",
    data=anscombe[anscombe.dataset == "I"],
    scatter_kws={"s": 60},
    ci=False,
)
plt.show()
sns.lmplot(
    x="x",
    y="y",
    data=anscombe[anscombe.dataset == "II"],
    scatter_kws={"s": 60},
    ci=False,
)
plt.show()

sns.lmplot(
    x="x",
    y="y",
    data=anscombe[anscombe.dataset == "II"],
    order=2,
    scatter_kws={"s": 60},
    ci=False,
)
plt.show()

sns.lmplot(
    x="x",
    y="y",
    data=anscombe[anscombe.dataset == "III"],
    order=2,
    scatter_kws={"s": 60},
    ci=False,
)
plt.show()

sns.lmplot(
    x="x",
    y="y",
    data=anscombe[anscombe.dataset == "III"],
    robust=True,
    scatter_kws={"s": 60},
    ci=False,
)
plt.show()

df = df.assign(big_tip=(df.tip / df.total_bill) > 0.15)

sns.lmplot(x="total_bill", y="big_tip", data=df)
plt.show()

sns.lmplot(x="total_bill", y="big_tip", data=df, logistic=True)
plt.show()

sns.lmplot(x="total_bill", y="big_tip", data=df, logistic=True, y_jitter=0.4)
plt.show()

sns.lmplot(x="total_bill", y="big_tip", data=df, logistic=True, y_jitter=0.1)
plt.show()


sns.lmplot(
    x="total_bill",
    y="tip",
    data=df,
    lowess=True,
    y_jitter=0.1,
    line_kws={"color": "red"},
)
plt.show()

sns.residplot(x="x", y="y", data=anscombe[anscombe.dataset == "I"])
plt.show()

sns.residplot(x="x", y="y", data=anscombe[anscombe.dataset == "II"])
plt.show()

import pandas as pd
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

penguins = sns.load_dataset("penguins")
penguins.columns
sns.barplot(data=penguins, x="species", y="body_mass_g")
plt.show()
penguins.species.value_counts()
penguins.groupby("species")["body_mass_g"].mean()


sns.barplot(data=penguins, x="species", y="body_mass_g", ci=None)
plt.show()
penguins.columns
sns.barplot(data=penguins, x="species", y="body_mass_g", hue="island", ci=None)
plt.show()

sns.barplot(
    data=penguins, x="species", y="body_mass_g", hue="island", ci=None, estimator=np.std
)
plt.show()

sns.barplot(data=penguins, x="species", y="body_mass_g", estimator=np.max)
plt.show()
penguins.groupby("species")["body_mass_g"].max()

sns.barplot(
    data=penguins,
    x="species",
    y="body_mass_g",
    estimator=np.max,
    order=["Adelie", "Chinstrap", "Gentoo"][::-1],
)
plt.show()
penguins.groupby("species")["body_mass_g"].max().index.tolist()
x = ["Adelie", "Chinstrap", "Gentoo"]
penguins.columns
sns.barplot(
    data=penguins, x="species", y="body_mass_g", estimator=np.max, hue="sex",
)
plt.show()

sns.barplot(
    data=penguins,
    x="species",
    y="body_mass_g",
    estimator=np.max,
    hue="sex",
    hue_order=["Male", "Female"],
    order=["Adelie", "Chinstrap", "Gentoo"][::-1],
)
plt.show()

sns.barplot(
    data=penguins,
    x="species",
    y="body_mass_g",
    estimator=np.max,
    hue="sex",
    hue_order=["Male", "Female"],
    order=["Adelie", "Chinstrap", "Gentoo"][::-1],
    palette="hot",
    edgecolor="aliceblue",
    lw=2,
)
plt.show()

penguins_sample = (
    penguins.dropna().groupby(["species", "sex"]).sample(3, random_state=10)
)

penguins_sample
temp = penguins_sample.groupby(["species", "sex"])["body_mass_g"].sum().reset_index()
sns.barplot(
    data=temp, x="species", y="body_mass_g", hue="sex", estimator=np.sum, ci=False,
)
plt.show()
temp = penguins_sample.groupby(["species", "sex"])["body_mass_g"].sum().unstack()

temp.plot(kind="bar", stacked=True)
plt.show()

diamonds = sns.load_dataset("diamonds")
sns.countplot(data=diamonds, x="color")
plt.show()

diamonds.cut.cat.categories
sns.countplot(
    data=diamonds, x="color", order=diamonds.color.value_counts().index.tolist()
)
plt.show()

sns.countplot(
    data=diamonds,
    x="color",
    hue="clarity",
    order=diamonds.color.value_counts().index.tolist(),
)
plt.show()


sns.countplot(
    data=diamonds,
    x="color",
    color="red",
    order=diamonds.color.value_counts().index.tolist(),
)
plt.show()

import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")
tips.columns
tips.dtypes

g = sns.pairplot(tips)
plt.show()

g = sns.pairplot(tips, kind="kde")

sns.pairplot(tips, diag_kind="kde")
plt.show()

sns.pairplot(tips, diag_kind="kde", corner=True)
plt.show()

sns.pairplot(tips, diag_kind="kde", markers="^", hue="sex")
plt.show()

sns.pairplot(tips, diag_kind="kde", markers="^", hue="sex", palette="bone")
plt.show()

sns.pairplot(tips, diag_kind="kde", markers="^", plot_kws={"color": "black"})
plt.show()

sns.pairplot(
    tips,
    diag_kind="kde",
    kind="reg",
    plot_kws={"line_kws": {"color": "red", "lw": 2}},
    diag_kws={"color": "brown", "lw": 3, "fill": False},
)
plt.show()
sns.kdeplot
help(sns.regplot)
help(sns.pairplot)

g = sns.pairplot(
    tips,
    diag_kind="kde",
    kind="scatter",
    diag_kws={"color": "brown", "lw": 3, "fill": False},
)
g.map_upper(sns.kdeplot, n_levels=6)
plt.show()

g = sns.pairplot(
    tips,
    diag_kind="kde",
    kind="scatter",
    diag_kws={"color": "brown", "lw": 3, "fill": False},
    vars=["total_bill", "tip"],
)
g.map_upper(sns.kdeplot, n_levels=6)
plt.show()

g = sns.pairplot(
    tips,
    diag_kind="kde",
    kind="reg",
    diag_kws={"color": "brown", "lw": 3, "fill": False},
    plot_kws={"ci": None, "scatter_kws": {"s": 1},},
    vars=["total_bill", "tip"],
)
plt.show()

g = sns.pairplot(
    tips,
    hue="sex",
    diag_kind="kde",
    kind="reg",
    diag_kws={"color": "brown", "lw": 3, "fill": False},
    plot_kws={"ci": None, "scatter_kws": {"s": 1},},
    vars=["total_bill", "tip"],
    palette="plasma",
)
plt.show()


geyser = sns.load_dataset("geyser")

geyser
sns.jointplot(data=geyser, x="waiting", y="duration")
plt.show()
g = sns.jointplot(data=geyser)

g = sns.jointplot(data=geyser, x="waiting", y="duration")
g.plot_marginals(sns.rugplot, height=1)
g.ax_joint.set_xlabel("")
g.ax_joint.set_ylabel("")
plt.show()


help(sns.jointplot)
g = sns.jointplot(data=geyser, x="waiting", y="duration", kind="kde")
g.plot_marginals(sns.histplot, height=1)
g.ax_joint.set_xlabel("")
g.ax_joint.set_ylabel("")
plt.show()


g = sns.jointplot(data=geyser, x="waiting", y="duration")
g.plot_marginals(sns.rugplot, height=-0.1, c="red", clip_on=False)
g.plot_joint(sns.kdeplot, c="black", levels=3)

g.ax_joint.set_xlabel("")
g.ax_joint.set_ylabel("")
g.ax_joint.set_xlim(30, 110)
g.ax_joint.set_ylim(0.5, 6)
plt.show()


g = sns.jointplot(data=geyser, x="waiting", y="duration")
g.plot_marginals(sns.rugplot, height=-0.1, c="red", clip_on=False)
g.plot_joint(sns.kdeplot, c="black", levels=3)

g.ax_joint.set_xlabel("")
g.ax_joint.set_ylabel("")
g.ax_joint.set_xlim(30, 110)
g.ax_joint.set_ylim(0.5, 6)
plt.show()


g = sns.jointplot(data=geyser, x="waiting", y="duration", kind="hist")
g.ax_joint.set_xlabel("")
g.ax_joint.set_ylabel("")
g.ax_joint.set_xlim(30, 110)
g.ax_joint.set_ylim(0.5, 6)
plt.show()

g = sns.jointplot(data=geyser, x="waiting", y="duration", kind="hist", hue="kind")
g.ax_joint.set_xlabel("")
g.ax_joint.set_ylabel("")
g.ax_joint.set_xlim(30, 110)
g.ax_joint.set_ylim(0.5, 6)
plt.show()
help(sns.jointplot)
help(sns.pairplot)

What’s my takeaway this time ?

seaborn is a library that allows one to plot univariate, bivariate relationships between various features present as columns in a pandas DataFrame. There are two types of functions in seaborn, one that yields a FacetGrid object and one that yields an axis object. You can choose to use the lower level functions if all you are looking to create, is a single figure. But if you want multiple figures, then displot, regplot and catplot could be very useful

For some one familiar with ggplot2, this is a good python library that will closely reflect grammar of graphics concepts. The fact that it works seamlessly with pandas objects might be a good reason to look at this library and get comfortable using the library.

At a high level, if one thinks of various kinds of visuals that one can display on a 2D plane, they can organized as follows

  • One dimensional plot
    • Histogram
    • ECDF plot
    • KDE
    • Rug plot
    • Bar plot
    • Count plot
  • Two dimensional - Both variables are numeric
    • Scatter
    • Line
    • Regression
    • Heatmap
  • Two dimensional - One numeric and other categorical
    • Box plot
    • Violin plot
    • Swarm plot
    • Strip plot
  • Two dimensional - generic
    • Pair plot
    • Joint plot
  • Embedding facet level graphs, which is by default in ggplot2 type libraries, but there are separate functions in seaborn
    • displot
    • relplot
    • catplot
    • PairGrid plot
    • JointGrid plot

Once you realize that the above covers probably 80pct of your plotting requirements, then all one has to figure out are the styling aspects of a graph such as

  • what should be the height, width and aspect ratio of the visual ?
  • what markers to use ?
  • what should be marker size ?
  • what color palette to use ?
  • what should be the font size ?
  • what line width to use ?
  • what colors to use to show specific sub components of a plot ?
  • If you are showing a rug plot, what should be the height of the rug plot ?
  • should one show a conditional plot ?
  • should one show a conditional and grid plot ?

By spending an hour or two on seaborn, a wonderfully designed library, one can get a good grasp of probably most of the visuals that you would end up either in your exploratory work or your final presentation.