simple_density.py
| FUNCTION | DESCRIPTION |
|---|---|
plot_simple_density |
Generates a 2D kernel density estimate (KDE) plot showing the relationship between pleasantness and presence scores in the given dataset. |
plot_simple_density
plot_simple_density(df, **kwargs)
Generates a 2D kernel density estimate (KDE) plot showing the relationship between pleasantness and presence scores in the given dataset.
This function computes a 2D KDE on a regular grid and plots the 50% highest-density region (HDR) as filled contours. Optionally, the underlying scattered points and the marginal
distributions along x and y can be added. If a grouping variable is specified, a separate density is computed for each category, with its own
colour and an automatic legend.
This function allows users to customise plot parameters though **kwargs
| PARAMETER | DESCRIPTION |
|---|---|
df
|
A DataFrame containing survey data. It must include at least the columns
TYPE:
|
**kwargs
|
Additional keyword arguments to override default plotting parameters, including:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
fig
|
The Matplotlib figure object of the generated plot.
TYPE:
|
ax
|
The corresponding axes object containing the scatter plot.
TYPE:
|
Examples:
>>> import pandas as pd
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from matplotlib.patches import Patch
>>> import smellscapy.plotting.utils as ut
>>> from smellscapy.databases.DataExample import load_example_data
>>> from smellscapy.surveys import validate
>>> from smellscapy.calculations import calculate_presence, calculate_pleasantness
>>> from smellscapy.plotting import plot_scatter
>>> df = load_example_data()
>>> df, excl_df = validate(df)
>>> df = calculate_presence(df)
>>> df = calculate_pleasantness(df)
>>> fig, ax = plot_simple_density(df, group_by_col = "Smell_source")
Source code in src/smellscapy/plotting/simple_density.py
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 | |