I have the following dictionary:

top = {'aaaa': {'โ˜น': 7, '๐Ÿ‘น': 12, '๐Ÿ˜ก': 6},
      'bbbb': {'๐Ÿ‘': 2, '๐Ÿ˜‰': 2, '๐Ÿ˜˜': 2},
      'cccc': {'โ˜น': 5, '๐Ÿ˜†': 3, '๐Ÿ™‚': 3},
      'dddd': {'๐ŸŒ': 8, '๐Ÿ˜ˆ': 7, '๐Ÿค—': 3},
      'eeee': {'โ˜บ': 3, '๐Ÿ˜‚': 5, '๐Ÿ˜”': 4},
      'ffff': {'โ˜น': 5, '๐Ÿ’ž': 5, '๐Ÿ˜ข': 5}}

Each 'aaaa' or 'bbbb' is the user's name, and his values is the emoji he is using the most. I want to plot a decent looking graph to visualize. After a few tries, this is my best work:

enter image description here

with the code:

import matplotlib.pyplot as plt

def top_emoji(top):
    fig, ax = plt.subplots(figsize=(8, 5))
    y = 9
    level = 0
    start = 9
    for name, dictionary in top.items():
        ax.text(start, y - level, name, fontsize=20)
        x = 3
        for emoj in dictionary.keys():
            ax.text(start - x, y - level, emoj, fontname='Segoe UI Emoji', fontsize=20)
            x += 1
        level += 1

    ax.axis([0, 10, 0, 10])

Which is terrible in my opinion. Any recommendations for improvements will be much appreciated.

  • \$\begingroup\$ Just to be clearโ€ฆ the scores are irrelevant? And it's OK to present each user's emojis in any order? \$\endgroup\$ Nov 18, 2017 at 18:44
  • \$\begingroup\$ Well I rather put the highest score first, closest to the person's name, but right now it doesn't really bother me. \$\endgroup\$
    – sheldonzy
    Nov 18, 2017 at 18:45

1 Answer 1


Your code might be a bit clearer without level & start, preferring to manipulate just x & y.

You might write a sorting helper function, and change the emoj loop to this:

    for x, emoj in enumerate(emoj_by_score(dictionary)):

You have some hard coded values that you could derive by inspecting the top input argument. On the whole, it doesn't seem so terrible. It is reasonably clear.


Your Answer

By clicking โ€œPost Your Answerโ€, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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