Coder Social home page Coder Social logo

Comments (5)

KirstieJane avatar KirstieJane commented on July 28, 2024

Thanks @wingedRuslan - can you add an example of the additional functions that seaborn heatmap gives us? I personally prefer the current version because I like the black line around the outside of the plot, and I can't think of options that heatmap will give us that are useful in this case. Happy to be wrong though!

from scona.

wingedRuslan avatar wingedRuslan commented on July 28, 2024

@KirstieJane, if the black line around the outside of the plot is the only reason, I could add this feature to the new function as well :)

you did this with the following line of code

    # Put a box around your data
    ax.add_patch(
     mpatches.Rectangle(
        (ax.get_xlim()[0], ax.get_ylim()[1]),
        ax.get_xlim()[1],
        ax.get_ylim()[0],
        fill=False,      # remove background
        color='k',
        linewidth=1) )

from scona.

wingedRuslan avatar wingedRuslan commented on July 28, 2024

@KirstieJane, the only difference (that we care about) could be concerning the improved colorbar:

  • in the existed version, the colorbar range is hardcoded to be [-1,0,1]. That's why only the diverging colormap can be used to plot corr_mat; You can see the output above if we use, for instance, sequential colormap.
  • in the seaborn version, we can adjust colormap with the vmin, vmax parameters
    vmin, vmax - Values to anchor the colormap, otherwise they are inferred from the data and other keyword arguments.
    cbar - Whether to draw a colorbar (although, not a problem to add this param to the existed version)
    cbar_kws - Keyword arguments for fig.colorbar
    Adjust colorbar properties
    This param I used to set custom labels to the colorbar (-1,0,1) to create the same plot as the existed version.

from scona.

wingedRuslan avatar wingedRuslan commented on July 28, 2024

Link to the existed function - view_corr_mat - here

from scona.

KirstieJane avatar KirstieJane commented on July 28, 2024

Thanks for the link @wingedRuslan! I like that function actually 😄

This is the code I was thinking of that's at the top of the tutorials:

# Read in sample data from the NSPN WhitakerVertes PNAS 2016 paper.
df, names, covars, centroids = datasets.NSPN_WhitakerVertes_PNAS2016.import_data()

# calculate residuals of the matrix df for the columns of names
df_res = scn.create_residuals_df(df, names, covars)

# create a correlation matrix over the columns of df_res
M = scn.create_corrmat(df_res, method='pearson')

# Initialise a weighted graph G from the correlation matrix M
G = scn.BrainNetwork(network=M, parcellation=names, centroids=centroids)

# Threshold G at cost 10 to create a binary graph with 10% as many edges as the complete graph G.
G10 = G.threshold(10)

M is the correlation matrix.

The correct way to threshold the graph is using the G.threshold() command because it makes a minimum spanning tree to make sure that every node is connected for any threshold (cost). BUT for visualization purposes that isn't super important, so we can just threshold using the np.percentile function as in the current code.

To be clear - we do not need to pass a graph G to the function. We can stick with giving it M or a dataframe etc.

The bin option is so that you can visualize the thresholded network as a (usually) black and white correlation matrix. It just sets all the values below the threshold to 0 and all those above to 1. This is what we do when we calculate the global measures.

So the current code looks great. Lets add vmin and vmax in whatever way you think is best (seaborn or adding those options to the current code), and maybe add a symmetric option (or whatever you used for the other colormaps to force vmin to be -vmax or vmax to be -vmin depending on which gives the largest range 😄

Thanks for checking!

from scona.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.