简体   繁体   中英

How to define points' labels using Pygal Scatterplot, pygal.XY?

I have a list of tuples (x,y) of a MDS projection result and I need to show the points names/labels. So I also have a list of labels.

For instance:

labels = ['a','b','c','d']
points = [(1,2),(1,3),(1,4),(4,5)]
xy_chart = pygal.XY(stroke=False,style=LightColorizedStyle)
xy_chart.title = 'MDS projection'
xy_chart.add('Result', points)

I saw a solution using metadata and dictionary for barcharts:

chart = pygal.Bar()
chart.add('Red', [{
  'value': 2,
  'label': 'This is red',
  'xlink': 'http://en.wikipedia.org/wiki/Red'}])
chart.add('Green', [{
  'value': 4,
  'label': 'This is green',
  'xlink': 'http://en.wikipedia.org/wiki/Green'}])

How could I do this using scatter plot XY function from Pygal?

You need to add a tuple for 'value'. For instance:

xy_chart = pygal.XY(stroke=False)
xy_chart.title = 'A Made Up Correlation Between Search Engines'
xy_chart.add('Group A', [{'value': (0, 0), 'label': 'google', 'xlink':'http://www.google.com'}, {'value': (22, 2), 'tooltip': 'bing', 'xlink':'http://www.bing.com'}])
xy_chart.add('Group B', [{'value': (12, 20), 'label': 'yahoo', 'xlink':'http://www.yahoo.com'}, {'value': (33, 12), 'tooltip': 'duckduckgo', 'xlink':'http://www.duckduckgo.com'}])
xy_chart.render()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM