Python tools for Emotions: Bokeh hextile, Violin chart

Modeling mind patterns can be a challenge when we are unable to find enough time to observe ourselves. Digital tools can enable viewing time-based snapshots of ourselves by creating powerful data visualizations of our emotions over a period of time. Such a model can be used towards our enlightenment- Color coded patterns in a hexbin plot using Bokeh Lib. Like this we can use many graphics tools to enhance our visual models in healthcare and technology.

Color coding our emotions
I found this particular chart very interesting to be used as a data visualization tool by various aspects- color coding, hex, visual - and simple coding. Sample piece of code found at Bokeh gallery- https://docs.bokeh.org/en/latest/docs/gallery/hex_tile.html



import numpy as np

from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.transform import linear_cmap
from bokeh.util.hex import hexbin

n = 50000
x = np.random.standard_normal(n)
y = np.random.standard_normal(n)

bins = hexbin(x, y, 0.1)

p = figure(title="Manual hex bin for 50000 points", tools="wheel_zoom,pan,reset",
           match_aspect=True, background_fill_color='#440154')
p.grid.visible = False

p.hex_tile(q="q", r="r", size=0.1, line_color=None, source=bins,
           fill_color=linear_cmap('counts', 'Viridis256', 0, max(bins.counts)))

output_file("hex_tile.html")

show(p)

An example application and sketch of such a hex chart-

We can define a color code where each color can mean a certain level of wellness- for example Colorcode = [yellow= Bright, blue = Sad, Dark blue = Depressed, Red=Angry, green=Happy]The size of the hexagon can also express the intensity of the emotion.

We can examine different aspects of our life and rate how we feel about each one of them - like physical wellness, mental wellness, spiritual wellness, social connectedness, financial stability etc and then plot them as a whole in this chart.  We can also relate each one of these levels to factors responsible for them- like Friends for social connectedness, Cooking for Happiness. The color dominance in our chart can be used to reflect overall wellness- like mostly yellow can mean Brightness in our lives. We can keep checking these over a period of time to see how different factors influence our happiness- some may be easy to guess and some may not. Then we can build our life around it.



CBT Progress Chart 
Bokeh Violin chart (https://docs.bokeh.org/en/0.10.0/docs/gallery/violin.html) implemented as a CBT (Cognitive Behavioral Therapy) progress chart.



The above chart can be used as a CBT progress chart for a person who is using CBT to observe their thoughts and add more positivity to their thought patterns. The above chart is plotted in Bokeh as a violin chart. A sample code is below-

import seaborn as sns

from bokeh import mpl
from bokeh.plotting import output_file, show

tips = sns.load_dataset("tips")

sns.set_style("whitegrid")

# ax = sns.violinplot(x="size", y="tip", data=tips.sort("size"))
# ax = sns.violinplot(x="size", y="tip", data=tips,
#                     order=np.arange(1, 7), palette="Blues_d")
# ax = sns.violinplot(x="day", y="total_bill", hue="sex",
#                     data=tips, palette="Set2", split=True,
#                     scale="count")
ax = sns.violinplot(x="day", y="total_bill", hue="sex",
                    data=tips, palette="Set2", split=True,
                    scale="count", inner="stick")
# ax = sns.violinplot(x="day", y="total_bill", hue="smoker",
#                     data=tips, palette="muted", split=True)
# ax = sns.violinplot(x="day", y="total_bill", hue="smoker",
#                     data=tips, palette="muted")

# planets = sns.load_dataset("planets")
# ax = sns.violinplot(x="orbital_period", y="method",
#                     data=planets[planets.orbital_period < 1000],
#                     scale="width", palette="Set3")

output_file("violin.html")

show(mpl.to_bokeh())
We can use the above chart in a scenario like this- I have a few situations in my life where I think obsessively, negatively and worry too much. My psychologist asks me to practice CBT to become aware of my patterns and create space for some positive thinking or alternate thinking and behaviors. Let there be 4 situations where I lose my mind- My exams, my arguments with my professor, my illness and my future. I practice CBT daily on these four situations noting my negative obsessive habitual thoughts, as well as possible and positive, alternate thoughts. As I observe my situations that give me the opportunity to practice alternate thinking I note how many times I was able to repeat myself (negative thought) and how many times I was able to practice my alternate thought. Once I start practising CBT let's assume I am still negative 15 times but positive 4 times. I also note the intensity of my emotions- how negative or how positive I feel with those situations.

Once this data is available the chart like above is plotted where I can see a visualization of my mind's habit patterns and also observe how much progress I made - plotted in green are the negative ones and brown, positive ones. I am also able to see if I was able to achieve any balance in my view or thinking - for example in the above chart the first (leftmost) situation depicts more balance between green and brown and the last (rightmost) shows the most imbalance- very negative and repetitive thoughts, very little positivity and very low frequency of positive thought.

Comments