-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlots.py
40 lines (32 loc) · 1.14 KB
/
Plots.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
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
# create a 3x3 matrix
matrix = np.array([[0.1, 0.2, 0.15],
[0.05, 0.3, 0.1],
[0.1, 0.15, 0.0]])
# create a meshgrid for the x and y coordinates
x, y = np.meshgrid(np.arange(3), np.arange(3))
# flatten the matrix into a 1D array
z = matrix.flatten()
# create a 3D plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.view_init(30, 30) # set the viewpoint
ax.bar3d(x.ravel(), y.ravel(), np.zeros_like(z), 0.9, 0.9, z, color='b', alpha=1)
# add labels and ticks
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Probability')
ax.set_xticks(np.arange(3) + 0.5)
ax.set_yticks(np.arange(3) + 0.5)
ax.set_xticklabels(['A', 'B', 'C'])
ax.set_yticklabels(['X', 'Y', 'Z'])
# set tick labels to be centered
ax.tick_params(axis='both', which='major', labelsize=14)
plt.setp(ax.get_xticklabels(), ha="center", rotation_mode="anchor")
plt.setp(ax.get_yticklabels(), ha="center", rotation_mode="anchor")
# add title
ax.set_title("Joint Probability", fontsize=16)
# show plot
plt.show()