2
$\begingroup$

This is how my data looks like:

Attr1: 0.5, 0.6 .. 0.9, 0.5, ... 0.9 (fluctuates 5 times) -> 25 data points

Attr2: 0.5, 0.5, 0.5, 0.5, 0.5, 0.6, 0.6, 0.6, 0.6, 0.6 ... (until 0.9) -> 25 data points

Attr3: (randomly changes between 0 and 1 continuously (e.g. 0.57) based on attr1 and attr2) -> 25 data points.

My question is how can I show on a single visaulization that when attr1 and and attr2 changes, then attr3 changes accordingly and the values for all of them?

The tool also doesn't matter. Python, excel, Google spreadsheets, I'm ok with all.

$\endgroup$
2
  • $\begingroup$ By "randomly changes between 0 and 1", do you mean that it can take any continuous value between 0 and 1 (0.1, 0.008, etc.), or that it can take only one of the two values 0 and 1? $\endgroup$
    – J-J-J
    Commented Oct 28, 2022 at 7:29
  • 1
    $\begingroup$ @JJJ It can take any continuous value, but there are 2 digits after the dot, in case it also makes a difference. $\endgroup$
    – JollyRoger
    Commented Oct 28, 2022 at 7:48

1 Answer 1

3
$\begingroup$

If I understand correctly what your dataset looks like, you could use a heatmap. It allows you to plot your data on three dimensions: horizontal, vertical, and color.

Here's an example with the Python's seaborn library:

import seaborn as sns
import pandas 
import random
#creating the dataset
random.seed(42)
df = pandas.DataFrame()
df["attribute 1"] = [0.5,0.6,0.7,0.8,0.9] * 5 
df["attribute 2"] = [0.5]*5 + [0.6]*5 + [0.7]*5 + [0.8]*5 + [0.9]*5 
#assuming attr3 = attr1 * attr2 + some random noise
df["attribute 3"] = df["attribute 1"] * df["attribute 2"] + [round(random.uniform(-0.05,0.05),2) for i in range(25)]
#tranforming if in a crosstable
crosstab = pandas.crosstab(df["attribute 1"], df["attribute 2"], df["attribute 3"], aggfunc=sum)
crosstab = crosstab.reindex(index=crosstab .index[::-1])
#creating the heatmap
cmap = sns.cm.rocket_r
sns.heatmap(crosstab, annot=True, cmap = cmap, 
        cbar_kws={'label': 'attritbute 3'})

Heatmap showing how attr1 and attr2 affects attr3. Attr1 is on the X axis, attr2 and the Y axis. Attr3 is on the "color" axis, tending to darker colors as it increases.

This heatmap shows that as attr1 and attr2 increase, attr3 tends to darker colors (which represent higher values of attr3). The code above assumed that your data was such as $attr3 = attr1 \times attr2 +ϵ$.

You'll probably want to customize this heatmap, by changing colors, adding some title, legend, or comments, etc. But you get the general idea.

I initially thought about a bubble chart, but it may be difficult to display the exact values of attr3 on it, and I find that with your data the difference of sizes between points (i.e. the values of attr3) is not immediately visible. The heatmap is more eye-catching to me. It might have been more relevant to use a bubble chart if attr3 had a wider range of values or if attr1 and attr2 had a lot of different values. But even in this case, I suspect that a heatmap would remain a good or even better option.

Anyway, below is an example of what a bubble chart would look like with your data, using size and color to show attr3 values. You can see that with your data, the result is very akin to a heatmap:

ax = sns.scatterplot("attribute 1", "attribute 2", size="attribute 3", 
                     hue="attribute 3", data=df,
                     hue_norm=(df["attribute 3"].min(), 
                               
                               df["attribute 3"].max(),),
                      palette=sns.color_palette("vlag", as_cmap=True)
                     )
sns.move_legend(ax, "upper left", bbox_to_anchor=(1, 1))
sns.despine()

Bubble plot of attr1 on the X axis, attr2 on the Y axis, and attr3 on the size axis. Point colors vary from blue for low values of attr3 (bottom left quadrant), to red for high values of attr3 (upper right quadrant)

$\endgroup$
2
  • 1
    $\begingroup$ Hey, great idea. Thank you! $\endgroup$
    – JollyRoger
    Commented Nov 1, 2022 at 21:17
  • $\begingroup$ @JollyRoger My pleasure, it was fun to think about this problem! $\endgroup$
    – J-J-J
    Commented Nov 1, 2022 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.