1

I would like visualise some data stored in a dictionary

foo = {'cat':5, 'dog':1, 'elephant':10} 

as a bubble plot, with bubble sizes corresponding to the values. Ideally I would like interactivity; when hovering mouse over bubble you see the name 'cat', for example.

Any recommendations and tips for how to achieve this?

An idea I had is to create a pandas dataframe, df =

 Animals Love x y 0 cat 5 0 0 1 dog 1 1 0 2 elephant 10 0 1 

where the x, y parameters are used to tell something like seaborn the location of the bubbles, and the 'Love' determines the size of the bubbles. This feels somewhat clunky, especially as I have many more than 3 rows. I would like it if the locations of the bubbles were chosen automatically.

Of course, this is just one idea, so any suggestions are very welcome!

2 Answers 2

1

I haven't found a simple way to do it with matplotlib but if you don't mind a browser display you can try mpld3. Here is an example:

import matplotlib.pyplot as plt import numpy as np import mpld3 fig, ax = plt.subplots(subplot_kw=dict(axisbg='#EEEEEE')) N = 10 # Animals Love x y # 0 cat 5 0 0 # 1 dog 1 1 0 # 2 elephant 10 0 1 x = np.array([0, 1, 0]) y = np.array([0, 0, 1]) s = np.array([5, 1, 0]) * 1000 # make circle looks bigger c = np.array(['red', 'green', 'blue']) labels = ['cat', 'dog', 'elephant'] scatter = ax.scatter(x, y, c=c, s=s, alpha=0.3) ax.grid(color='white', linestyle='solid') ax.set_title("Scatter Plot (with tooltips!)", size=20) tooltip = mpld3.plugins.PointLabelTooltip(scatter, labels=labels) mpld3.plugins.connect(fig, tooltip) mpld3.show() 

Result (label shown on hover):

example

Sign up to request clarification or add additional context in comments.

Comments

1

You can use the bokeh python library for interactive visualization.

http://docs.bokeh.org/en/latest/docs/gallery/categorical.html

Combine the hover functionality in figure and plot circles/bubbles in place of rectangles as in the above tutorial.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.