1

I'm trying to visualize the result of rolling two D6 on a pygal histogram viewed in browser. When mousing over one of the bars, i get number overlap. example of overlap i'll include my code below.

import pygal
from die import Die

# Create two D6 dice
die_1 = Die()
die_2 = Die()

# Make some results and store in a list.
results = []
for roll_num in range(1000):
    result = die_1.roll() + die_2.roll()
    results.append(result)

# Analyze the results.
frequencies = []
max_result = die_1.num_sides + die_2.num_sides
for value in range(2, max_result+1):
    frequency = results.count(value)
    frequencies.append(frequency)

# Visualize the results.
hist = pygal.Bar()
hist.force_uri_protocol = 'http'

hist.title = "Results of rolling two D6 dice 1000 times."
hist.x_labels = ['2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
hist.x_title = "Result"
hist.y_title = "Frequency of Result"

hist.add('D6 + D6', frequencies)
hist.render_to_file('die_visual.svg')
Cody
  • 11
  • 1
  • the Die class that I'm importing is basically just a bit of code to create a default D6 and the .roll() obviously. – Cody Jan 29 '18 at 19:38
  • I copied your code and when I run it, the tool tips behave as expected. Each bar displays it's own tooltip and none overlap with the other columns. I'm on a Mac (I see your on Ubuntu), but I tried both Firefox and Safari and both render correctly. To help debug a bit further, what version of pygal, python, and firefox are you using as the code appears to work on my setup. – Alan H Feb 05 '18 at 21:49
  • Thanks for your help. I'm using python 3.6.3 in a virtual env and pygal 2.4. My firefox is version is 12.0 – Cody Feb 09 '18 at 16:57
  • I'm running python 3.6.3 and pygal 2.4 as well. However, my firefox is much newer than yours (58.0.1). It's possible this is an issue with firefox as I don't see anything wrong with your code. I have a few ideas to debug further. 1) Have you upgrade firefox to a newer version, and see if that works. 2) Upload your actual .svg file and post a link to it and I'll see if the tooltips work for me. 3) I can send you the .svg I generated and we can see if it renders correctly on your system. – Alan H Feb 09 '18 at 19:53
  • Thank you for all of your help. I ran "sudo apt-get upgrade" and ubuntu told me my all of my software is up to date. I'm not sure how that happens if i'm some 46 updates behind. I can't find a way to upload my .svg. Sorry for being so 'noob' at this. – Cody Feb 11 '18 at 17:28
  • Here is some info about upgrading firefox that might help you: https://askubuntu.com/questions/333411/updating-or-uninstalling-and-reinstalling-firefox-on-linux – Alan H Feb 13 '18 at 16:48

1 Answers1

0

I've copied your code and I'm able to create an .svg file where the tooltips work correctly when viewed in two different browsers (Firefox and Safari).

From the comments thread we are both using Python 3.6.3 and Pygal 2.4. The only difference appears to be browser version (and OS).

I suggest upgrading firefox to something newer and see if that solves your problem.

Alan H
  • 3,021
  • 4
  • 25
  • 24