def pcaplot(x=None, y=None, z=None, labels=None, var1=None, var2=None, var3=None, axlabelfontsize=9, axlabelfontname="Arial", figtype='png', r=300, show=False, plotlabels=True, dim=(6, 4), theme=None): if theme == 'dark': general.dark_bg() if x is not None and y is not None and z is None: assert var1 is not None and var2 is not None and labels is not None, "var1 or var2 variable or labels are missing" plt.subplots(figsize=dim) for i, varnames in enumerate(labels): plt.scatter(x[i], y[i]) if plotlabels: plt.text(x[i], y[i], varnames, fontsize=10) general.axis_labels("PC1 ({}%)".format(var1), "PC2 ({}%)".format(var2), axlabelfontsize, axlabelfontname) general.get_figure(show, r, figtype, 'pcaplot_2d', theme) elif x is not None and y is not None and z is not None: assert var1 and var2 and var3 and labels is not None, "var1 or var2 or var3 or labels are missing" # for 3d plot fig = plt.figure(figsize=dim) ax = fig.add_subplot(111, projection='3d') for i, varnames in enumerate(labels): ax.scatter(x[i], y[i], z[i]) if plotlabels: ax.text(x[i], y[i], z[i], varnames, fontsize=10) ax.set_xlabel("PC1 ({}%)".format(var1), fontsize=axlabelfontsize, fontname=axlabelfontname) ax.set_ylabel("PC2 ({}%)".format(var2), fontsize=axlabelfontsize, fontname=axlabelfontname) ax.set_zlabel("PC3 ({}%)".format(var3), fontsize=axlabelfontsize, fontname=axlabelfontname) general.get_figure(show, r, figtype, 'pcaplot_3d', theme)