klotz: matplotlib*

Bookmarks on this page are managed by an admin user.

0 bookmark(s) - Sort by: Date ↓ / Title / - Bookmarks from other users for this tag

  1. In your example if you use PCA to initialize your t-SNE you get widely spaced centroids; if you use random initialization you'll get tiny centroids and an uninteresting picture.
  2. import numpy as np
    import matplotlib.pyplot as plt
    from scipy.interpolate import griddata

    # Load data from CSV
    dat = np.genfromtxt('dat.xyz', delimiter=' ',skip_header=0)
    X_dat = dat :,0 »
    Y_dat = dat :,1 »
    Z_dat = dat :,2 »

    # Convert from pandas dataframes to numpy arrays
    X, Y, Z, = np.array( » ), np.array( » ), np.array( » )
    for i in range(len(X_dat)):
    X = np.append(X,X_dat i » )
    Y = np.append(Y,Y_dat i » )
    Z = np.append(Z,Z_dat i » )

    # create x-y points to be used in heatmap
    xi = np.linspace(X.min(),X.max(),1000)
    yi = np.linspace(Y.min(),Y.max(),1000)

    # Z is a matrix of x-y values
    zi = griddata((X, Y), Z, (xi None,: » , yi :,None » ), method='cubic')

    # I control the range of my colorbar by removing data
    # outside of my range of interest
    zmin = 3
    zmax = 12
    zi (zi<zmin) | (zi>zmax) » = None

    # Create the contour plot
    CS = plt.contourf(xi, yi, zi, 15, cmap=plt.cm.rainbow,
    vmax=zmax, vmin=zmin)
    plt.colorbar()
    plt.show()
    2017-07-30 Tags: , , , , by klotz
  3. You can fix the problem on Mac OS X Mavericks and Yosemite by doing the following:

    cd ~/.matplotlib/
    fc-list # Should take a couple minutes.
    After fc-list finishes running you will be able to import the package using import matplotlib.pyplot as plt.
    2017-07-29 Tags: , , , by klotz
  4. for i, txt in enumerate(n):
    ax.annotate(txt, (z i » ,y i » ))
    2016-05-19 Tags: , , , by klotz
  5. I used a Python t-SNE library to reduce the 200 feature dimensions for each word to 2 dimensions and plotted them in matplotlib. I saved out the x/y coordinates for each word in the book, so that I can show those words on the graph as you mouse over the replaced (blue) words.

Top of the page

First / Previous / Next / Last / Page 3 of 0 SemanticScuttle - klotz.me: Tags: matplotlib

About - Propulsed by SemanticScuttle