-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscatter_plot.py
More file actions
75 lines (60 loc) · 3.29 KB
/
scatter_plot.py
File metadata and controls
75 lines (60 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import plot_data
import plot_data.colors as colors
import random
# A script showing scatter plots instantiations.
elements = []
SHAPES = ['round', 'square', 'triangle', 'ellipse']
COLORS = [colors.RED, colors.BLUE, colors.GREEN, colors.YELLOW, colors.ORANGE, colors.VIOLET]
for i in range(50):
random_shape = SHAPES[random.randint(0, len(SHAPES) - 1)]
random_color = COLORS[random.randint(0, len(SHAPES) - 1)]
elements.append({'mass': random.uniform(0, 50),
'length': random.uniform(0, 100),
'shape': random_shape,
'color': random_color
})
scatterplot = plot_data.Scatter(elements=elements,
x_variable='mass', y_variable='length')
# The previous scripts shows the simplest way of creating a scatterplot.
# However, many options are available for further customization
# First of all, apart from tooltips' information, the user can customize
# the style. 'text_style' modifies the text while 'surface_style'
# changes the tooltip's interior. Tooltips are rounded-rectangle-shaped and the radius of the
# vertices can also be changed.
text_style = plot_data.TextStyle(text_color=colors.GREY,
font_size=10,
font_style='sans-serif')
surface_style = plot_data.SurfaceStyle(color_fill=colors.LIGHTVIOLET, opacity=0.3)
custom_tooltip = plot_data.Tooltip(attributes=['mass', 'length'],
surface_style=surface_style,
text_style=text_style,
tooltip_radius=10)
# Then, points' appearance can be modified through point_style attribute
point_style = plot_data.PointStyle(color_fill=colors.LIGHTGREEN,
color_stroke=colors.VIOLET,
stroke_width=0.5,
size=2, # 1, 2, 3 or 4
shape='square') # 'circle', 'square' or 'crux'
# Finally, axis can be personalized too
graduation_style = plot_data.TextStyle(text_color=colors.BLUE, font_size=10,
font_style='Arial')
axis_style = plot_data.EdgeStyle(line_width=0.5, color_stroke=colors.ROSE,
dashline=[])
axis = plot_data.Axis(nb_points_x=7, nb_points_y=5,
graduation_style=graduation_style,
axis_style=axis_style
)
# a tooltip is drawn when clicking on a point. Users can choose what information
# they want to be displayed.
tooltip = plot_data.Tooltip(attributes=['mass', 'length', 'shape', 'color'])
# Heatmap settings
heatmap = plot_data.Heatmap([4,2], colors=[colors.YELLOW, colors.ORANGE, colors.RED])
# Now, here is the new scatterplot
customized_scatterplot = plot_data.Scatter(x_variable='mass', y_variable='shape',
point_style=point_style,
elements=elements,
axis=axis,
tooltip=custom_tooltip,
heatmap=heatmap)
# if debug_mode is True, set it to False
plot_data.plot_canvas(plot_data_object=customized_scatterplot, debug_mode=True)