1

I was running some code in spyder, but decided that I needed it to be more presentable, so I copied and pasted it directly into notebook. When I did, the plots changed.

here is the code that I copied:

from sklearn.mixture import GMM
import pandas as pd
from sklearn import datasets
import matplotlib.pyplot as plt
import itertools
import warnings

warnings.filterwarnings("ignore")

iris = datasets.load_iris()
x = iris.data
y = iris.target
lala = []

gmm = GMM(n_components=3).fit(x)
labels = gmm.predict(x)
fig, axes = plt.subplots(4, 4)
Superman = iris.feature_names
markers = ["*" , "+" , "s", "o"]
colors = ["red", "green", "blue", "black"]
Mi=[]
for i in range(150):
  Mi.append(markers[y[i]])


Z_Values = (gmm.predict_proba(x))

goalie = []
for i in range(len(Z_Values)):
    row = Z_Values[i,:]
    idx = row.argsort()
    if(row[idx[-1]] - row[idx[-2]]< .15):
        goalie.append(i)
# Comment this out when you are doing checks
labels[goalie] =  3

for i in range(4):
    for j in range(4):
        for k in range(x.shape[0]):
            if(i != j):
                axes[i, j].scatter(x[k, i], x[k, j], c=colors[labels[k]], marker = markers[y[k]], s=.5, cmap='viridis')
                axes[i, j].tick_params(axis='both', which='both', bottom='off', top='off', labelbottom='off', right='off', left='off', labelleft='off')

            else:
                if k > 1:
                    pass
                axes[i,j].text(0.1, 0.3, Superman[i], fontsize = 7)
                axes[i, j].tick_params(axis='both', which='both', bottom='off', top='off', labelbottom='off', right='off', left='off', labelleft='off')

In spyder the subplots created are 3 colors (red, green, blue) and show up normally. When I use notebook, only the green points show. Here is an example of how it looks (sorry for the potato quality):

enter image description here

Any idea why this is happening? What is different between spyder and notebook that causes this? I notice that If I save my picture in spyder as a .png this also happens.

Travasaurus
  • 601
  • 1
  • 8
  • 26
  • 1
    You also get only a single color if this is run as a .py file... – duhaime Sep 14 '18 at 23:01
  • Here is an imgur link to how the plot SHOULD look: https://imgur.com/a/LxP4A1J – Travasaurus Sep 14 '18 at 23:02
  • I ran it in spyder and got the correct version /: whats different? @duhaime – Travasaurus Sep 14 '18 at 23:03
  • 1
    can you ditch your IDE and run this as a Python script and post a new imgur link? It's an interesting question. – duhaime Sep 14 '18 at 23:10
  • 2
    You set the markersize much too small. Use `s=10` or at least a value bigger than 1. In general this approach is rather inefficient; you create one scatter plot per point. [The solution I provided the other day](https://stackoverflow.com/a/52303895/4124317) would be more suitable for this many points. – ImportanceOfBeingErnest Sep 14 '18 at 23:15
  • I get the correct picture. It looks the same as the above link. If I change the file type to .png then it becomes the wrong ones again. Is this a file type issue?? @duhaime – Travasaurus Sep 14 '18 at 23:19
  • That worked! @ImportanceOfBeingErnest I'll switch it over now. Thanks! – Travasaurus Sep 14 '18 at 23:22
  • 1
    At the end (added after the fact) I save it as a .pdf then as a .png plt.savefig("Accuracy_Plot.png", bbox_inches='tight', dpi = 100) plt.close(fig) @duhaime – Travasaurus Sep 14 '18 at 23:22

0 Answers0