0

I would like to draw in Python an "amphitheatre" (like in the pictures of the US senate -- image below) such that when a user hovers around a seat, a box is displayed over the cursor with some "seat-specific" information. Where to begin? Are there specific packages that facilitate the creation of such interactive objects?

US Senate example EDIT: My "final" goal is to create a gui visualizing a dataframe with the columns

name | gender | do they like music

and then the user can choose to color the "seats" by gender (blue for men, red for women, gray for other), or by their love to music (green for yes, red for no). In the beginning I have thought using tkinter but drawing the circles in the exact form of an amphitheatre have proven to be a hard task (for instance this thread deals with drawing of a single circle) and the final output has appeared to be rather ugly.

  • It is expected that people make an honest attempt at solving the problem before seeking help in SO. Please, provide more info on what you've found, what you've tried and what went wrong. See [how to ask](https://stackoverflow.com/help/how-to-ask). – MatBBastos Sep 12 '21 at 15:00
  • @MatBBastos thanks for the comment. I have edited the question and added some more details .Hope it helps. – Denis Marcinkov Sep 12 '21 at 15:20
  • For the shape, I believe you need to define exactly what it is that you want. Which parameters are relevant? Then, you can make an abstraction layer to generate points in 2D space that represent each seat. Possible inputs for this function could be horizontal length, total number of seats, distance between seats, number of layers.. and more. – MatBBastos Sep 12 '21 at 16:15
  • About the 'hover action', would a simple tooltip do the trick? Check [this](https://stackoverflow.com/questions/20399243/display-message-when-hovering-over-something-with-mouse-cursor-in-python) out. – MatBBastos Sep 12 '21 at 16:15
  • You have three problems: how to compute the locations for points to get the amphitheatre shape, how to plot circles in these locations and how to get the hover to display extra info. I guess that the first one will be on you, bokeh or plotly will handle the remaining two. – psarka Sep 12 '21 at 15:36
  • The type of plot you want is a `Parliament` plot. There are a few packages you can use to help out related to plitical science, e.g. [PolySci Kit](https://pythonawesome.com/a-python-package-for-political-science-appointment-and-election-analysis/). You can also check [this question](https://stackoverflow.com/questions/28917150/parliamentary-seats-graph-colors-and-labels) for an idea of the algorithm, although it is in R. – bicarlsen Sep 12 '21 at 17:43
  • @bicarlsen Thanks for the idea but unless I'm missing something PolySci does not allow to add hover text. – Denis Marcinkov Sep 13 '21 at 08:35
  • @psarka so you suggest a scatter plot with increased marker size? – Denis Marcinkov Sep 13 '21 at 08:36
  • @MatBBastos about simple hover: I suppose it requires tkinter. About the shape: the number of seats is some prefixed constant which simplifies things hence I can just draw circles/markers located on arcs of 3 concentric circles. – Denis Marcinkov Sep 13 '21 at 08:40
  • @DenisMarcinkov, PolySci Kit plotting methods return the axis, so you should be able to retroactively add in interaction. If that doesn't suit your needs, you can also look at the [source code](https://github.com/andrewtavis/poli-sci-kit) for ideas of your own implementation. – bicarlsen Sep 13 '21 at 10:16

0 Answers0