-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
59 lines (46 loc) · 1.88 KB
/
plot.py
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
import matplotlib.pyplot as plt
import seaborn as sns
from pandas.plotting import parallel_coordinates
import plotly.express as px
import plotly.io as pio
palette = sns.color_palette("bright", 10)
# Some of this code modified from https://github.com/OpenClassrooms-Student-Center/Multivariate-Exploratory-Analysis
def addAlpha(colour, alpha):
'''Add an alpha to the RGB colour'''
return (colour[0], colour[1], colour[2], alpha)
def display_parallel_coordinates_centroids(df, num_clusters):
'''Display a parallel coordinates plot for the centroids in df'''
# Create the plot
fig = plt.figure(figsize=(12, 5))
title = fig.suptitle("Parallel Coordinates plot for the Centroids", fontsize=18)
fig.subplots_adjust(top=0.9, wspace=0)
# Draw the chart
parallel_coordinates(df, 'predicted_cluster', color=palette)
# Stagger the axes
ax = plt.gca()
for tick in ax.xaxis.get_major_ticks()[1::2]:
tick.set_pad(20)
def display_parallel_coordinates(df, num_clusters):
'''Display a parallel coordinates plot for the clusters in df'''
# Select data points for individual clusters
cluster_points = []
for i in range(num_clusters):
cluster_points.append(df[df.predicted_cluster == i])
# Draw the chart
pc = px.parallel_coordinates(data_frame=df, color='predicted_cluster')
pio.renderers.default = 'browser'
pc.show()
# Stagger the axes
ax = plt.gca()
for tick in ax.xaxis.get_major_ticks()[1::2]:
tick.set_pad(20)
def display_parallel_coordinates_centroids(df, num_clusters):
'''Display a parallel coordinates plot for the centroids in df'''
# Draw the chart
pc = px.parallel_coordinates(data_frame=df, color='predicted_cluster')
pio.renderers.default = 'browser'
pc.show()
# Stagger the axes
ax = plt.gca()
for tick in ax.xaxis.get_major_ticks()[1::2]:
tick.set_pad(20)