2
$\begingroup$

I really like how this visualization represents the survey participants.

Is any tool for that? (Or R/python library?)

enter image description here

$\endgroup$
4
$\begingroup$

My go to library would be matplotlib, with which it is relatively easy to generate something similar.

I don't have the correct font family to render the exact output as above, but this hopefully illustrates the point
enter image description here

Source Code

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


# Create the data to plot on
# create a 2d array of evenly-spaced points on a grid
xy_range = np.arange(10.)
data = pd.DataFrame([[x, y] for x in xy_range for y in xy_range], columns=['X', 'Y'])

# color the points
# all green first and then with exceptions
data['color'] = 'green'
data.loc[(data['X']>=0)&(data['Y']==1), 'color'] = 'yellow'
data.loc[(data['X']>=8)&(data['Y']==2), 'color'] = 'yellow'
data.loc[(data['X']>=6)&(data['Y']==0), 'color'] = 'blue'

# We'll use this to calculate axis fractions
max_x = data['X'].max()
max_y = data['Y'].max()

fig, currAX = plt.subplots(figsize=(5,5), facecolor='lightgray')

# plot/mark each point as an annotation
# we do this so we can get a custom emoji instead a marker
for x0, y0, color in zip(data['X'], data['Y'], data['color']):    
    plt.annotate(s=u'\u263B', xy=(x0/max_x, y0/max_y), fontname='STIXGeneral', color=color, size=15, ha='center', va='center')

# clear the axis lables, ticks, and lines        
currAX.get_xaxis().set_visible(False) 
currAX.get_yaxis().set_visible(False)       
plt.axis('off')

plt.show();
| improve this answer | |
$\endgroup$
3
$\begingroup$

With Wolfram Language you may use "Icon" Entity and ConstantArray to create lists of "Crayola" ColorData colored icons and display with Multicolumn 24 columns wide.

palette = <|"SeaGreen" -> 135, "Razzmatazz" -> 146, "Yellow" -> 18, "TurquoiseBlue" -> 13|>;
Multicolumn[
 Flatten@
  KeyValueMap[
    With[{i =
        Graphics[{ColorData["Crayola", #1], List @@ Entity["Icon", "MensRoom"]["Image"]},
         Background -> Black,
         ImageSize -> 12]
       },
      ConstantArray[i, #2]
      ] &
    ]@palette,
 24,
 Spacings -> .2,
 Frame -> True,
 FrameStyle -> Directive[Thickness[3], Black],
 Background -> Black,
 Appearance -> "Horizontal"
 ]

Mathematica graphics

Update

The above can be generalised into a function that takes an Association of colours to number of icons, a set of graphics primitives for the icon (icons are FilledCurves), and some additional display parameters.

ClearAll[iconChart]
Options[iconChart] = {Options[Multicolumn], Options[Graphics]};
SetOptions[iconChart,
  {
   Background -> Black,
   ImageSize -> 12,
   Spacings -> .2,
   Frame -> True,
   FrameStyle -> Directive[Thickness[3], Black],
   Appearance -> "Horizontal"
   }];
iconChart[pallet_, icon_, columns_, opts : OptionsPattern[iconChart]] :=
 Multicolumn[
  Flatten@
   KeyValueMap[
     With[{i =
         Graphics[{#1, icon}, 
          Frame -> None, 
          FilterRules[{opts, Options[iconChart]}, Options[Graphics]]]
        },
       ConstantArray[i, #2]
       ] &
     ]@pallet,
  columns,
  FilterRules[{opts, Options[iconChart]}, {Options[Multicolumn]}]
  ]

Then the above can be charted with

iconChart[
 <|
  ColorData["Crayola", "SeaGreen"] -> 135,
  ColorData["Crayola", "Razzmatazz"] -> 146,
  ColorData["Crayola", "Yellow"] -> 18,
  ColorData["Crayola", "TurquoiseBlue"] -> 13
  |> ,
 List @@ Entity["Icon", "MensRoom"]["Image"], 
 24
]

Adding random colour and icon selection generates a different chart on each evaluation.

iconChart[
 AssociationThread[
  RandomSample[
   Values@KeyDrop["Black"]@ColorData["Crayola", "ColorRules"], 5],
  RandomInteger[{3, 15}, 5]
  ],
 List @@ RandomEntity["Icon"]["Image"],
 10,
 ImageSize -> 30]

For example,

Mathematica graphics

Mathematica graphics

Mathematica graphics

and so on.

Hope this helps.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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