Package: ipysigma
ipysigmaAJupyterwidget usingsigma.jsandgraphologyto render interactive networks directly within the result of a notebook cell.Live Demoipysigmahas been designed to work with eithernetworkxorigraph.ipysigmalets you customize a large number of the graph's visual variables such as: node color, size, label, border, halo, pictogram, shape and edge color, size, type, label etc.For an exhaustive list of what visual variables you may tweak, check the "Available visual variables" part of the documentation.ipysigmais also able to display synchronized & interactive "small multiples" of a same graph to easily compare some of its features.SummaryInstallationQuick startExamplesCompute a Louvain partition and use it as node colorUse networkx/igraph/custom metrics as visual variablesDisplay a pandas DataFrame as a graphComparing two features of a graphMore examples: functional testing notebooksWhat data can be used as visual variableVisual variables and kwargs naming rationaleScales, palettes and gradientsWidget-side metricsFrequently asked questionsWhy are there so few labels displayed?Why are some of my categories mapped to a dull grey?I gave colors to node_color but arbitrary colors are displayed by the widget insteadMy computer sounds like an airplane taking offSome of my widgets only display labels or a glitchy black boxMy graph is ugly, make it beautiful like GephiAvailable visual variablesnode_colornode_color_saturationnode_sizenode_labelnode_label_sizenode_label_colornode_border_sizenode_border_rationode_border_colornode_pictogramnode_pictogram_colornode_shapenode_halo_sizenode_halo_coloredge_coloredge_typeedge_sizeedge_curvenessedge_labelAPI ReferenceSigma#.get_layout#.get_camera_state#.get_selected_node#.get_selected_edge#.get_selected_node_category_values#.get_selected_edge_category_values#.render_snapshot#.to_htmlSigma.write_htmlSigma.set_defaultsSigmaGrid#.addHow to citeInstallationYou can install usingpip:pipinstallipysigmaYou will also need to install eithernetworkxorigraph.If you are using an older version of Jupyter, you might also need to enable the nbextension likewise:jupyternbextensionenable--py--sys-prefixipysigma# You might need one of those other commandsjupyternbextensionenable--py--useripysigma
jupyternbextensionenable--py--systemipysigmaIf you want to useipysigmaonGoogle Colab, you will need to enable widget output using the following code:fromgoogle.colabimportoutputoutput.enable_custom_widget_manager()Remember you can always install packages in Colab by executing the following command in a cell:!pip install networkx ipysigmaQuick startUsing networkximportnetworkxasnxfromipysigmaimportSigma# Importing a gexf graphg=nx.read_gexf('./my-graph.gexf')# Displaying the graph with a size mapped on degree and# a color mapped on a categorical attribute of the nodesSigma(g,node_size=g.degree,node_color='category')Using igraphimportigraphasigfromipysigmaimportSigma# Generating a graphg=ig.Graph.Famous('Zachary')# Displaying the graph with a size mapped on degree and# a color mapped on node betweenness centrality, using# a continuous color scale named "Viridis"Sigma(g,node_size=g.degree,node_color=g.betweenness(),node_color_gradient='Viridis')ExamplesCompute a Louvain partition and use it as node coloripysigmais able to compute metrics on the widget side usinggraphology. As such, you can ask it to compute e.g. a Louvain partitioning if you don't want or cannot do it on the python side.For more information about available metrics and how to specify them, checkthispart of the documentation.Sigma(g,node_metrics=["louvain"],node_color="louvain")# Renaming the target attributeSigma(g,node_metrics={"community":"louvain"},node_color="community")# Passing custom parametersSigma(g,node_metrics={"community":{"name":"louvain","resolution":1.5}},node_color="community")Use networkx/igraph/custom metrics as visual variablesUse networkx metrics:importnetworkxasnxg=nx.path_graph(5)Sigma(g,node_size=nx.eigenvector_centrality(g))Use igraph metrics:importigraphasigg=ig.Graph.GRG(5,0.5)Sigma(g,node_size=g.pagerank(),node_color=g.connected_components())Use custom metrics:importnetworkxasnxdefeven_or_odd(node):returnnode%2==0g=nx.path_graph(5)Sigma(g,node_color=even_or_odd)Readthisfor an exhaustive list of what can be used as visual variables.Display a pandas DataFrame as a graphConverting tabular data to a graph is not obvious. So for this, we advise to use helper functions found in our other library pythonpelote.In this first example, we create a graph from a DataFrame of edges:importpandasaspdfrompeloteimportedges_table_to_graph# Alice invited Bob and Chloe. Bob invited Chloe twice.df=pd.DataFrame({"hosts":["Alice","Alice","Bob","Bob"],"guests":["Bob","Chloe","Chloe","Chloe"]})g=edges_table_to_graph(df,edge_source_col="hosts",edge_target_col="guests",count_rows_as_weight=True,directed=True)Sigma(g,edge_size='weight')Using pelote again, you can also create a bipartite network (students and their professors, for example) with thetable_to_bipartite_graphfunction:importpandasaspdfrompeloteimporttable_to_bipartite_graphdf=pd.DataFrame({"professor":["A","A","A","B","B","B","B"],"student":["C","D","E","C","F","G","H"],})g=table_to_bipartite_graph(df,'student','professor',node_part_attr='status')Sigma(g,node_color='status',default_node_size=10,show_all_labels=True)Comparing two features of a graphLet's say we have a graph of websites that we categorized by type and language and we want to compare the distribution of those categories on the graph's topology. We could use node color for language and border color for type but you will quickly see that this is probably not readable.To solve this kind of problems and enable its users to easily compare multiple features of a graph,ipysigmaexposes aSigmaGridwidget that arranges multiple synchronized views of the same graph on a grid:fromipysigmaimportSigmaGrid# Views to display can be specified through the `views` kwarg, expecting# a list of dicts of keyword arguments to give to the underlying Sigma widgets:SigmaGrid(g,views=[{"node_color":"type"},{"node_color":"type"}])# You can do the same by using the `#.add` method of the grid to# dynamically add views:SigmaGrid(g).add(node_color="lang").add(node_color="type")# Any kwarg passed to the grid directly will be used by all of the views.# This is useful to avoid repetition:SigmaGrid(g,node_size=g.degree,views=[{"node_color":"type"},{"node_color":"type"}])# You can of course display more than 2 views# By default the grid has 2 columns and will wrap to new rows,# but you can change the number of columns using the `columns` kwarg:SigmaGrid(g,columns=3,views=[{"node_size":g.degree},{"node_size":g.in_degree},{"node_size":g.out_degree}])More examples: functional testing notebooksIf you want comprehensive examples of the widget's visual variables being used,
you can read the notebooks foundhere, which serve as functional tests to the library.What data can be used as visual variableThere are several ways to specify what you want to use as visual variables
(readthisfor a detailed explanation).Here is the exhaustive list of what is possible:Name of a node or edge attribute# Let's say your nodes have a "lang" attribute, we can use its modalities as values for# a categorical color palette:Sigma(g,node_color='lang')Node or edge mapping# You can store the data in a mapping, e.g. a dictionary, likewise:node_lang={'node1':'en','node2':'fr',...}Sigma(g,node_color=node_lang)# For edges, the mapping's key must be a 2-tuple containing source & target nodes.# Note that for undirected graphs, the order of nodes in the tuple# does not make any difference as both will work.edge_type={('node1','node2'):'LIKES',('node2','node3'):'LOVES'}Arbitrary iterable# Any arbitrary iterable such as generators, ranges, numpy vectors,# pandas series etc. will work. The only requirement is that they should# follow the order of iteration of nodes or edges in the graph, so we may# align the data properly.# Creating a 0 to n generic label for my nodesSigma(g,node_label=range(len(g)))# Random size for my edgesSigma(g,edge_size=(random()for_ing.edges))# Numpy vectorSigma(g,node_size=np.random.rand(len(g)))# Pandas seriesSigma(g,edge_size=df.edge_weights)Partition# A partition, complete or not, but not overlapping, of nodes or edges:# Must be a list of lists or a list of sets.communities=[{2,3,6},{0,1},{4,6}]Sigma(g,node_color=communities)networkx/igraph degree view# Mapping node size on degree is as simple as:Sigma(g,node_size=g.degree)igraph VertexClustering# IGraph community detection / clustering methods return a VertexClustering objectSigma(g,node_color=g.connected_components())Sigma(g,node_color=g.community_multilevel())Arbitrary callable# Creating a label for my nodesSigma(g,node_label=lambdanode:'Label of '+str(node))# Using edge weight as size only for some source nodesSigma(g,edge_size=lambdau,v,a:attr['weight']ifg.nodes[u]['part']=='main'else1)# Node callables will be given the following arguments:#   1. node key#   2. node attributes# Edge callables will be given the following arguments:#  1. source node key#  2. target node key#  3. edge attributes# Note that given callables may choose to take any number of those arguments.# For instance, the first example only uses the first argument but still works.Set# A set will be understood as a binary partition with nodes or edges being# in it or outside it. This will be mapped to a boolean value, with `True`# meaning the node or edge was in the partition.# This will display the nodes 1, 5 and 6 in a color, and all the other ones# in a different color.Sigma(g,node_color={1,5,6})Visual variables and kwargs naming rationaleipysigmalets its users tweak a large number ofvisual variables. They all work through a similar variety of keyword arguments given to theSigmawidget.Inipysigmavisual variables can be given:categorical data, which means they will map category values to discrete visualization values such as a node's category being associated with a given color.continuous data, which means they will map numerical values to a range of sizes or a gradient of colors, like when representing a node's degree by a size on screen.kwargs naming rationaleTo be able to be drawn on screen, every visual variable must use values that have a meaning for the the widget's visual representation. For colors, it might be a HTML color name such as#fa65eaorcyan. For sizes, it might be a number of pixels etc.If you know what you are doing and want to giveipysigmathe same "raw" values as those expected by the visual representation directly, all variables have kwargs starting byraw_, such asraw_node_color.But if you wantipysigmato map your arbitrary values to a suitable visual representation, all variables have a kwarg without any prefix, for instancenode_color.In which case, if you use categorical data,ipysigmacan generate or use palettes to map the category values to e.g. colors on screen. You can always customize the palette or mapping using a kwarg suffixed with_paletteor_mappingsuch asnode_color_paletteornode_shape_mapping.And if you use numerical data, then values will be mapped to an output range, usually in pixels, that can be configured with a kwarg suffixed with_rangesuch asnode_size_range. Similarly, if you want to map numerical data to a gradient of colors, you will find kwarg suffixed with_gradientsuch asnode_color_gradient.Sometimes, some values might fall out of the represented domain, such as non-numerical values for continuous variables, or categories outside of the colors available in the given palette. In which case there always exists a kwarg prefixed withdefault_, such asdefault_node_color. A neat trick is also to use those kwargs as a way to indicate a constant value if you want all your edges to have the same color for instance, or your nodes to have the same size in pixels.Finally, it's usually possible to tweak the way numerical values will be mapped from their original domain to the visual one. This is what you do, for instance, when you choose to use a logarithmic scale on a chart to better visualize a specific distribution. Similarly, relevantipysigmavisual variables give access to a kwarg suffixed_scale, such asnode_color_scalethat lets you easily switch from a linear to a logarithmic or power scale etc. (for more information about this, checkthisin the next part of the documentation).To summarize, let's finish with two exhaustive examples: node color & node size.Categorical or continuous variable: node color as an examplenode_color: this kwarg expects some arbitrary values related to your nodes. Those values can be given in multiple ways listedhere. By default,node_coloris a categorical variable. Hence, given values will be mapped to suitable colors, from a palette generated automatically for you. If you want your data to be interpreted as continuous instead, you will need to give a gradient to the variable throughnode_color_gradient.raw_node_color: this kwarg does not expect arbitrary values but CSS colors instead. This way you can always regain full control on the colors you want for your nodes if none ofipysigmautilities suit your particular use-case.default_node_color: thedefault_kwargs always expect a value that will be used in the final representation, so here a CSS color, that will be used if a node category is not found in the color palette or if a node value is not numerical and we are using a gradient.node_color_palette: by default,ipysigmausesiwanthueto automatically generate fitting color palettes for the categories present in the given data. But sometimes you might want to customize the colors used. In which case this kwarg expects either a dictionary mapping category values to a CSS color such as{'en': 'blue, 'fr': 'red'}or the name of a categorical color scheme fromd3-scale-chromaticsuch asTableau10orRdYlBufor instance.node_color_gradient: if you want to use a color gradient for your node to represent continuous data, you will need to give this kwarg either a 2-tuple containing the "lowest" and "highest" color such as("yellow", "red")or the name of a continuous color gradient fromd3-scale-chromaticsuch asInfernoorYlGnfor instance.node_color_scale: finally, if you gave a gradient tonode_color_gradientand want to apply a nonlinear scale to the given data, you can pass the name of the scale to use such aslogor a 2-tuple containing the name of the scale and an optional param such as the scale's base in the case of a logarithmic scale. Here is a binary log scale for instance:("log", 2).Continuous variable: node size as an examplenode_size: this kwarg expects some arbitrary numerical values related to your nodes. Those values can be given in multiple ways listedhere. Then they will be mapped using a scale given tonode_size_scaleto a range in pixels given tonode_size_rangebefore being used on screen.raw_node_size: if you want to bypass the scale and the range altogether, this kwarg directly takes values to be considered as pixels on screen.default_node_size: if no relevant value can be found for a node, or if said value is not a valid number, the widget will use this size, expressed in pixels, instead.node_size_scale: if you want to apply a nonlinear scale to the given data, you can pass the name of the scale to use such aslogor a 2-tuple containing the name of the scale and an optional param such as the scale's base in the case of a logarithmic scale. Here is a binary log scale for instance:("log", 2).node_size_range: this kwarg lets you customize the output range in pixels we should map the node numerical values to. For instance, if we want to have our nodes to have sizes between1pixel and25pixels, we would give it(1, 25). Note that most visual variables have a default range and this kwarg can usually be omitted if the defaults suit you.For a comprehensive view of the available visual variables, the values they expect and how they can be customized, readthisnext part of the documentation.Scales, palettes and gradientsAvailable scaleslin: linear scale, used by default when scale is not specified.log: logarithmic scale. Takes an optional base (eby default).log+1: logarithmic scale incrementing your values by one. This is a well-known visualization trick designed to avoid issues with zeros, which is often the case when using some typical node metrics. Takes an optional base (eby default)..pow: power scale. Takes an optional exponent (2by default).sqrt: square root scale (same as power scale but with inverted exponent). Takes an optional exponent (2by default).All the_scalekwargs can take the following:Nothing (the default), then the scale remains linear:node_size_scale=None.The name of the scale directly:node_size_scale="log".A 2-tuple containing the name of the scale and its parameter:node_size_scale=("log", 2).Color palettesBy default, color palettes are generated for you byipysigmausingiwanthue.ipysigmawill first count the number of distinct categories to represent, sort them by frequency and generate a palette of up to10colors for the most used ones. The other one will use the default one given to the relevantdefault_kwarg such asdefault_node_colorfor instance.Note that this maximum number of10can be increased using themax_categorical_colorskwarg.Note also that the palette generation is seeded using the mapped attribute name in the data so that the palette is always the same (if the name and the category count remains the same), but is different from one attribute to the other.If you don't wantipysigmato generate color palettes for you, you can give your own palette through the relevant_palettekwarg such asnode_color_palette, or use somed3-scale-chromaticone (they have names starting withscheme).Here is the full list of those palettes supported byipysigma:Accent,Blues,BrBG,BuGn,BuPu,Category10,Dark2,GnBu,Greens,Greys,OrRd,Oranges,PRGn,Paired,Pastel1,Pastel2,PiYG,PuBu,PuBuGn,PuOr,PuRd,Purples,RdBu,RdGy,RdPu,RdYlBu,RdYlGn,Reds,Set1,Set2,Set3,Spectral,Tableau10,YlGn,YlGnBu,YlOrBr,YlOrRd.Color gradientsColor gradients can be defined as a range from "lowest" to "highest" color, e.g.("yellow", "red).They can also be taken from anyd3-scale-chromaticcontinuous gradient (they have names starting withinterpolate).Here is the full list of those gradients supported byipysigma:Blues,BrBG,BuGn,BuPu,Cividis,Cool,CubehelixDefault,GnBu,Greens,Greys,Inferno,Magma,OrRd,Oranges,PRGn,PiYG,Plasma,PuBu,PuBuGn,PuOr,PuRd,Purples,Rainbow,RdBu,RdGy,RdPu,RdYlBu,RdYlGn,Reds,Sinebow,Spectral,Turbo,Viridis,Warm,YlGn,YlGnBu,YlOrBr,YlOrRd.Widget-side metricsSinceipysigmais usinggraphology, it can also draw from its library of graph theory metrics.As such, thenode_metricsenables you to ask your widget to compute node metrics on its own and use to map the result on any visual variable.Here is how you can specify metrics to be computed:# node_metrics expects an iterable of metrics to compute:Sigma(g,node_metrics=["louvain"],node_color="louvain")# They can be specified by name, but you can also specify through# a dictionary if you need parameters for the metrics:Sigma(g,node_metrics=[{"name":"louvain","resolution":1.5}],node_color="louvain")# You can also give a dictionary mapping resulting attribute name to# the metric to compute if you don't want to map the result on an attribute# having the same name as the metric:Sigma(g,node_metrics={"community":"louvain"},node_color="community")Sigma(g,node_metrics={"community":{"name":"louvain","resolution":1.5}},node_color="community")Available node metrics & their parameterslouvain: Louvain algorithm for community detection (through modularity optimization)resolution?float[1]: resolution parameter.Frequently asked questionsWhy are there so few labels displayed?Labels are costly to render and can negate the benefit of using a WebGL renderer such as sigma.js to render interactive graphs. As such, sigma.js relies on a constant size grid to select the "worthiest" labels to display, after taking camera zoom into account.You can tweak the parameters of this grid usinglabel_grid_cell_sizeandlabel_density. Decreasing the first one or increasing the second one will result in more labels being displayed.Also, by default, the label of a node is displayed only if its size in pixels is larger than a threshold. You can change that threshold using thelabel_rendered_size_thresholdkwarg.Finally, if you don't want to deal with all this nonsense and just want to display all labels because you know what you are doing and don't care about performance, you can just useshow_all_labels=Trueinstead.Why are some of my categories mapped to a dull grey?Whenipysigmagenerates palettes for you, it only uses up to10colors by default. This number can be increased using themax_categorical_colorskwarg. For more information about palette generation, readthispart of the documentation.Some designer told me (while holding a baseball bat) that it is unwise to have more than 10 categorical colors because you won't be able to distinguish them anymore. My hands are tied. Don't ask me to change this.I gave colors to node_color but arbitrary colors are displayed by the widget insteadnode_colordoes not expect colors per se but arbitrary data that will be mapped to a suitable color palette for you. If you want to give colors directly, useraw_node_colorinstead. For more information about the visual variables kwarg naming rationale, readthispart of the documentation.My computer sounds like an airplane taking offDon't forget to turn off the layout when it has converged (the pause button on the left). There is no convincing way to automatically detect when layout has converged so we must rely on you, the user, to indicate when it's done.If you want to start the layout automatically when instantiating the widget and make sure it will automatically stop after, say, 10 seconds, usestart_layout=10.Some of my widgets only display labels or a glitchy black boxYour GPU can only render so many webgl canvases in your browser tabs. So if you created too many widgets (this depends on the specifics of your computer and graphics card), it may gracefully deal with the situation by erasing the graph (but not the labels since those are rendered using 2d canvases) or by glitching to death.My graph is ugly, make it beautiful like GephiUsedefault_edge_type="curve",node_border_color_from="node",label_size=g.degreeandlabel_font="cursive"and you should have a dazzling Gephi graph.Available visual variablesnode_colorTypeCategorical or continuous.Raw valuesHTMLnamed coloror hex color or rgb/rgba color. Examples:red,#fff,#a89971,rgb(25, 25, 25),rgba(25, 145, 56, 0.5)Related kwargsnode_colorraw_node_colordefault_node_colornode_color_palettenode_color_gradientnode_color_scalenode_color_saturationTypeContinuous.Raw valuesA percentage of color saturation. Examples:0.1,0.96.Related kwargsnode_color_saturationraw_node_color_saturationdefault_node_color_saturationnode_color_saturation_rangenode_color_saturation_scalenode_sizeTypeContinuous.Raw valuesA node size, i.e. a circle radius, in pixels, with default camera (not zoomed nor unzoomed).Related kwargsnode_sizeraw_node_sizedefault_node_sizenode_size_rangenode_size_scalenode_labelTypeRaw only.Raw valuesA text label.Related kwargsnode_labelraw_node_labeldefault_node_labelnode_label_sizeTypeContinuous.Raw valuesA font size for the label text, in pixels.Related kwargsnode_label_sizeraw_node_label_sizedefault_node_label_sizenode_label_size_rangenode_label_colorTypeCategorical.Raw valuesHTMLnamed coloror hex color or rgb/rgba color. Examples:red,#fff,#a89971,rgb(25, 25, 25),rgba(25, 145, 56, 0.5)Related kwargsnode_label_colorraw_node_label_colordefault_node_label_colornode_label_color_palettenode_border_sizeTypeContinuous.Raw valuesA border size, in pixels, with default camera (not zoomed nor unzoomed).Note that this border size will be added to the node's radius.Related kwargsnode_border_sizeraw_node_border_sizedefault_node_border_sizenode_border_size_rangeNotesBorders are only shown on screen if anode_border_sizeOR anode_border_ratioAND anode_border_colorare defined.node_border_ratioTypeContinuous.Raw valuesA border ratio, in percentage, with default camera (not zoomed nor unzoomed).Note that this border ratio will eat the node's size.Related kwargsnode_border_ratioraw_node_border_ratiodefault_node_border_rationode_border_ratio_rangeNotesBorders are only shown on screen if anode_border_sizeOR anode_border_ratioAND anode_border_colorare defined.node_border_colorTypeCategorical or continuous.Raw valuesHTMLnamed coloror hex color or rgb/rgba color. Examples:red,#fff,#a89971,rgb(25, 25, 25),rgba(25, 145, 56, 0.5)Related kwargsnode_border_colorraw_node_border_colordefault_node_border_colornode_border_color_palettenode_border_color_gradientnode_border_color_scaleNotesBorders are only shown on screen if anode_border_sizeOR anode_border_ratioAND anode_border_colorare defined.node_pictogramTypeCategorical.Raw valuesThe name of any Google Material Icon as listedhere(the name must be lowercase and snake_case, e.g. the name "Arrow Drop Done" should be given toipysigmaasarrow_drop_done).Alternatively, one can also give urls of publicly accessible svg icons such ashttps://fonts.gstatic.com/s/i/short-term/release/materialsymbolsoutlined/arrow_drop_down/default/48px.svgRelated kwargsraw_node_pictogramdefault_node_pictogramNotesPictograms are only shown on screen ifnode_pictogramANDnode_pictogram_colorare defined.node_pictogram_colorTypeCategorical.Raw valuesHTMLnamed coloror hex color or rgb/rgba color. Examples:red,#fff,#a89971,rgb(25, 25, 25),rgba(25, 145, 56, 0.5)Related kwargsnode_pictogram_colorraw_node_pictogram_colordefault_node_pictogram_colornode_pictogram_color_paletteNotesPictograms are only shown on screen ifnode_pictogramANDnode_pictogram_colorare defined.node_shapeTypeCategorical.Raw valuesThe name of a supported shape such as:circle,triangle,square,pentagon,star,hexagon,heartorcloud.Alternatively, if you are feeling adventurous, it can also be the name of any Google Material Icon as listedhere(the name must be lowercase and snake_case, e.g. the name "Arrow Drop Done" should be given toipysigmaasarrow_drop_done).Finally, one can also give urls of publicly accessible svg icons such ashttps://fonts.gstatic.com/s/i/short-term/release/materialsymbolsoutlined/arrow_drop_down/default/48px.svgRelated kwargsnode_shaperaw_node_shapedefault_node_shapenode_shape_mappingNoteNode shapes cannot be used with borders nor pictograms nor halos, as of yet.node_halo_sizeTypeContinuous.Raw valuesA halo size offset in pixels, with default camera (not zoomed nor unzoomed). The full halo radius will therefore be its size + its node's radius.Related kwargsnode_halo_sizeraw_node_halo_sizedefault_node_halo_sizenode_halo_size_rangenode_halo_size_scalenode_halo_colorTypeCategorical or continuous.Raw valuesHTMLnamed coloror hex color or rgb/rgba color. Examples:red,#fff,#a89971,rgb(25, 25, 25),rgba(25, 145, 56, 0.5)Related kwargsnode_halo_colorraw_node_halo_colordefault_node_halo_colornode_halo_color_palettenode_halo_color_gradientnode_halo_color_scaleedge_colorTypeCategorical or continuous.Raw valuesHTMLnamed coloror hex color or rgb/rgba color. Examples:red,#fff,#a89971,rgb(25, 25, 25),rgba(25, 145, 56, 0.5)Related kwargsedge_colorraw_edge_colordefault_edge_coloredge_color_paletteedge_color_gradientedge_color_scaleedge_typeedge_sizeTypeContinuous.Raw valuesAn edge thickness in pixels, with default camera (not zoomed nor unzoomed).Related kwargsedge_sizeraw_edge_sizedefault_edge_sizeedge_size_rangeedge_size_scaleedge_curvenessTypeContinuous.Raw valuesA percentage. Note that it can go beyond1and that0will make the edge disappear.Related kwargsdefault_edge_curvenessedge_labelTypeRaw only.Raw valuesA text label.Related kwargsedge_labelraw_edge_labeldefault_edge_labelAPI ReferenceSigmaArgumentsgraphnx.AnyGraph or ig.AnyGraph- networkx or igraph graph instance to explore.namestr, optionalNone- name of the graph.heightint, optional500- height of the widget container in pixels.background_colorstr, optional"white"- css color to use as the graph's background.raw_heightstr, optionalNone- raw css height. Can be useful in some html embedding scenarios. Only use this if you know what you are doing.start_layoutbool or float, optionalFalse- whether to automatically start the layout algorithm when mounting the widget. If a number is given instead, the layout algorithm will start and automatically stop after this many seconds.node_metricsIterable or Mapping, optionalNone- node metrics to be computed by graphology by the widget's JavaScript code. Currently only supports "louvain" for community detection.layout_settingsdict, optionalNone- settings for the ForceAtlas2 layout (listed here:https://graphology.github.io/standard-library/layout-forceatlas2#settings.clickable_edgesbool, optionalFalse- whether to allow user to click on edges to display their information. This can have a performance cost on larger graphs.process_gexf_vizbool, optionalTrue- whether to process gexf files viz data for node & edges.max_categorical_colorsint, optional10- max number of colors to be generated for a categorical palette. Categories, ordered by frequency, over this maximum will use the default color.hide_info_panelbool, optionalFalse- whether to hide the information panel to the right of the widget.hide_searchbool, optionalFalse- whether to hide the search bar to the right of the widget.hide_edges_on_movebool, optionalFalse- whether to hide the edges when the graph is being moved. This can be useful to improve performance when the graph is too large.sync_keystr, optional- Key used by the widget to synchronize events between multiple instances of views of a same graph. Prefer usingSigmaGridwhen able, it will handle this advanced aspect of the widget for you.sync_targetsIterable, optional("layout", "camera", "selection", "hover")- Names of targets to synchronize through thesync_keykwarg. Targets include "layout", "camera", "selection" and "hover".camera_statedict, optional{"x": 0.5, "y": 0.5, "ratio": 1, "angle": 0}- Initial state for the widget's camera (which can be retrieved using the#.get_camera_statemethod).selected_nodestr or int, optionalNone- Key of the initially selected node in the widget (can be retrieved using the#.get_selected_nodemethod).selected_edgetuple, optionalNone- (source, target) tuple of the initially selected edge in the widget (can be retrieved using the#.get_selected_edgemethod).selected_node_category_valuesIterable, optionalNone- list of selected node category values (can be retrieved using the#.get_selected_node_category_valuesmethod).selected_edge_category_valuesIterable, optionalNone- list of selected edge category values (can be retrieved using the#.get_selected_edge_category_valuesmethod).label_fontstr, optional"sans-serif"- font to be used with labels.label_densityint, optional1- number of labels to display per grid cell for default camera zoom.label_grid_cell_sizeint, optional250- size in pixels of a square cell in the label selection grid.label_rendered_size_thresholdint, optionalNone- minimum actual rendered size (after camera zoom operations) a node must have on screen for its label to be allowed to be displayed. If None, the threshold will be inferred based on the maximum node size of your graph.show_all_labelsbool, optionalFalse- macro setting making sure most, if not all, labels get displayed on screen. Might have an impact on performance with larger graphs.layoutMapping, optionalNone- node positions, expressed as a{node: {x, y}mapping.node_colorVariableData, optionalNone- data to be used as categorical or continuous node color.raw_node_colorVariableData, optional"color"- raw data (css colors) to be used for node colors.node_color_gradientIterable or str, optionalNone- gradient of colors to map to, for instance: (("yellow", "red")), or name of a d3 continuous color scale (found here:https://github.com/d3/d3-scale-chromatic#readme), for instance: "Viridis". If given, node color will be interpreted as continuous rather than categorical.node_color_scaletuple or str, optionalNone- scale to use for node color. Can be a tuple containing the name of the scale and an additional param such as an exponent, or just the name of the scale to use: e.g.("log", 2)or"pow". Available scales include:"lin","log","log+1","pow"&"sqrt". If None is given, scale will default to"lin"for linear.node_color_paletteMapping or str, optionalNone- either a mapping from category values to css colors or the name of a d3 categorical color scale (found here:https://github.com/d3/d3-scale-chromatic#readme).default_node_colorstr, optional"#999"- default color for nodes.node_color_saturationVariableData, optionalNone- data to be used as continuous node color saturation.raw_node_color_saturationVariableData, optionalNone- raw data (percentage) to be used for node color saturation.node_color_saturation_scaletuple or str, optionalNone- scale to use for node color saturation. Can be a tuple containing the name of the scale and an additional param such as an exponent, or just the name of the scale to use: e.g.("log", 2)or"pow". Available scales include:"lin","log","log+1","pow"&"sqrt". If None is given, scale will default to"lin"for linear.node_color_saturation_rangeIterable, optional(0, 1)- range of percentages to map to, for instance:(0, 0.7).default_node_color_saturationstr, optionalNone- default color saturation for nodes.node_border_colorVariableData, optionalNone- data to be used as categorical or continuous node border color.raw_node_border_colorVariableData, optional"color"- raw data (css colors) to be used for node border colors.node_border_color_gradientIterable or str, optionalNone- gradient of colors to map to, for instance: (("yellow", "red")), or name of a d3 continuous color scale (found here:https://github.com/d3/d3-scale-chromatic#readme), for instance: "Viridis". If given, node border color will be interpreted as continuous rather than categorical.node_border_color_paletteMapping or str, optionalNone- either a mapping from category values to css colors or the name of a d3 categorical color scale (found here:https://github.com/d3/d3-scale-chromatic#readme).node_border_color_fromstr, optionalNone- optionally select node border color from the following options: "node".default_node_border_colorstr, optional- default color for node borders.node_border_sizeVariableData, optionalNone- data to be used as continuous node border size.raw_node_border_sizeVariableData, optionalNone- raw data (size in pixels) to be used for node border sizes.node_border_size_rangeIterable, optional(1, 5)- range of sizes in pixels to map to, for instance:(1, 15).default_node_border_sizeint or float, optional1- default size for node borders.node_border_ratioVariableData, optionalNone- data to be used as continuous node border ratio.raw_node_border_ratioVariableData, optionalNone- raw data (ratio in pixels) to be used for node border ratios.node_border_ratio_rangeIterable, optional(0.1, 0.5)- range of ratios in pixels to map to, for instance:(1, 15).default_node_border_ratioint or float, optional0.1- default ratio for node borders.raw_node_pictogramVariableData, optionalNone- raw data (pictogram name, as found here:https://fonts.google.com/iconsor publicly accessible svg icon url) to be used for node pictograms.default_node_pictogramstr, optionalNone- default pictogram for nodes.node_pictogram_colorVariableData, optionalNone- data to be used as categorical or continuous node pictogram color.raw_node_pictogram_colorVariableData, optional"color"- raw data (css colors) to be used for node pictogram colors.node_pictogram_color_paletteMapping or str, optionalNone- either a mapping from category values to css colors or the name of a d3 categorical color scale (found here:https://github.com/d3/d3-scale-chromatic#readme).default_node_pictogram_colorstr, optional"black"- default color for node pictograms.node_shapeVariableData, optionalNone- data to be used as categorical data to be mapped to node shapes.raw_node_shapeVariableData, optionalNone- raw data (shape name, or pictogram name as found here:https://fonts.google.com/iconsor publicly accessible svg icon url) to be used as node shapes.node_shape_mappingMapping, optional- mapping from category values to node shapes.default_node_shapestr, optionalNone- default shape for nodes.node_halo_colorVariableData, optionalNone- data to be used as categorical or continuous node halo color.raw_node_halo_colorVariableData, optional"color"- raw data (css colors) to be used for node halo colors.node_halo_color_gradientIterable or str, optionalNone- gradient of colors to map to, for instance: (("yellow", "red")), or name of a d3 continuous color scale (found here:https://github.com/d3/d3-scale-chromatic#readme), for instance: "Viridis". If given, node halo color will be interpreted as continuous rather than categorical.node_halo_color_paletteMapping or str, optionalNone- either a mapping from category values to css colors or the name of a d3 categorical color scale (found here:https://github.com/d3/d3-scale-chromatic#readme).default_node_halo_colorstr, optional"red"- default color for node halos.node_halo_sizeVariableData, optionalNone- data to be used as continuous node halo size.raw_node_halo_sizeVariableData, optionalNone- raw data (size in pixels) to be used for node halo sizes.node_halo_size_rangeIterable, optional(0, 20)- range of sizes in pixels to map to, for instance:(1, 15).default_node_halo_sizeint or float, optional0- default size for node halos.node_sizeVariableData, optional"size"- data to be used as continuous node size.raw_node_sizeVariableData, optionalNone- raw data (size in pixels) to be used for node sizes.node_size_rangeIterable, optional(3, 15)- range of sizes in pixels to map to, for instance:(1, 15).node_size_scaletuple or str, optionalNone- scale to use for node size. Can be a tuple containing the name of the scale and an additional param such as an exponent, or just the name of the scale to use: e.g.("log", 2)or"pow". Available scales include:"lin","log","log+1","pow"&"sqrt". If None is given, scale will default to"lin"for linear.default_node_sizeint or float, optionalNone- default size for nodes.node_labelVariableData, optionalNone- data to be used as node label.raw_node_labelVariableData, optional"label"- raw data (label string) to be used for node labels.default_node_labelstr, optionalNone- default label for nodes.node_label_sizeVariableData, optionalNone- data to be used as continuous node label size.raw_node_label_sizeVariableData, optionalNone- raw data (size in pixels) to be used for node label sizes.node_label_size_rangeIterable, optional(8, 25)- range of sizes in pixels to map to, for instance:(1, 15).default_node_label_sizeint or float, optional12- default size for node labels.node_label_colorVariableData, optionalNone- data to be used as categorical or continuous node label color.raw_node_label_colorVariableData, optionalNone- raw data (css colors) to be used for node label colors.node_label_color_paletteMapping or str, optionalNone- either a mapping from category values to css colors or the name of a d3 categorical color scale (found here:https://github.com/d3/d3-scale-chromatic#readme).default_node_label_colorstr, optional"black"- default color for node labels.node_zindexVariableData, optionalNone- numerical data used to sort nodes before rendering. Nodes having a higher zindex will be drawn on top of nodes having a lower one.edge_colorVariableData, optionalNone- data to be used as categorical or continuous edge color.raw_edge_colorVariableData, optional"color"- raw data (css colors) to be used for edge colors.edge_color_gradientIterable or str, optionalNone- gradient of colors to map to, for instance: (("yellow", "red")), or name of a d3 continuous color scale (found here:https://github.com/d3/d3-scale-chromatic#readme), for instance: "Viridis". If given, edge color will be interpreted as continuous rather than categorical.edge_color_scaletuple or str, optionalNone- scale to use for edge color. Can be a tuple containing the name of the scale and an additional param such as an exponent, or just the name of the scale to use: e.g.("log", 2)or"pow". Available scales include:"lin","log","log+1","pow"&"sqrt". If None is given, scale will default to"lin"for linear.edge_color_paletteMapping or str, optionalNone- either a mapping from category values to css colors or the name of a d3 categorical color scale (found here:https://github.com/d3/d3-scale-chromatic#readme).default_edge_colorstr, optional"#999"- default color for edges.default_edge_typestr, optionalNone- default type used to draw edges. Can be selected from"rectangle","line","curve","arrow"&"triangle". Will raise if"arrow"or"triangle"is selected with an undirected graph. If None, will default to"rectangle".edge_sizeVariableData, optional"size"- data to be used as continuous edge size.raw_edge_sizeVariableData, optionalNone- raw data (size in pixels) to be used for edge sizes.edge_size_rangeIterable, optional(3, 15)- range of sizes in pixels to map to, for instance:(1, 15).edge_size_scaletuple or str, optionalNone- scale to use for edge size. Can be a tuple containing the name of the scale and an additional param such as an exponent, or just the name of the scale to use: e.g.("log", 2)or"pow". Available scales include:"lin","log","log+1","pow"&"sqrt". If None is given, scale will default to"lin"for linear.default_edge_sizeint or float, optionalNone- default size for edges.default_edge_curvenessstr, optional0.25- curveness factor for edges whendefault_edge_typeis"curve".edge_labelVariableData, optionalNone- data to be used as edge label.raw_edge_labelVariableData, optional"label"- raw data (label string) to be used for edge labels.edge_weightVariableData, optional- numerical data to be used as edge weight for weighted metrics & layout computations (distinct from size, which is used for rendering).edge_zindexVariableData, optionalNone- numerical data used to sort egdes before rendering. Egdes having a higher zindex will be drawn on top of egdes having a lower one.#.get_layoutMethod returning the layout of the graph, i.e. the current node positions in the widget, as a dict mapping nodes to their{x, y}coordinates.#.get_camera_stateMethod returning the current camera state of the widget, as a{x, y, ratio, angle}dict.#.get_selected_nodeMethod returning the currently selected node if any orNone.#.get_selected_edgeMethod returning the currently selected edge as a(source, target)tuple if any orNone.#.get_selected_node_category_valuesMethod returning a set of currently selected node category values orNone.#.get_selected_edge_category_valuesMethod returning a set of currently selected edge category values orNone.#.render_snapshotMethod rendering the widget as an rasterized image in the resulting cell.#.to_htmlMethod rendering the widget as a standalone HTML file that can be hosted statically elsewhere.ArgumentspathPathLike or file: where to save the HTML file.Sigma.set_defaultsStatic method that can be used to override some default values of theSigmaclass kwargs.Argumentsheightint, optional: default widget height in pixels.background_colorstr, optional: default background color.max_categorical_colorsint, optional: default maximum number of colors for generated palettes.node_size_rangetuple, optional: default size range in pixels for nodes.edge_size_rangetuple, optional: default size range in pixels for edges.Sigma.write_htmlStatic method taking the same kwargs asSigmaand rendering the widget as a standalone HTML file that can be hosted statically elsewhere.Argumentsgraphnx.AnyGraph or ig.AnyGraph: graph to represent.pathPathLike or file: where to save the HTML file.fullscreenbool, optional[False]: whether to display the widget by taking up the full space of the screen. IfFalse, will follow the givenheight.**kwarg: any kwarg accepted bySigma.SigmaGridArgumentsgraphnx.AnyGraph or ig.AnyGraph- networkx or igraph graph instance to visualize.columnsint, optional2- maximum number of views to display in a line.sync_keystr, otpionalNone- synchronization key to use. If not given, one will be automatically generated by the grid.viewslist, optionalNone- list of kwarg dicts that will be used to instantiate the underlying Sigma views as an alternative to using the#.addmethod.**kwargs- any other kwarg will be passed as-is to Sigma views.#.addMethod one can use as an alternative or combined toSigmaGridconstructor'sviewskwarg to add a newSigmaview to the grid. It takes any argument taken bySigmaand returns self for easy chaining.SigmaGrid(g,node_color='category').add(node_size=g.degree).add(node_size='occurrences')How to citeGuillaume Plique. (2022). ipysigma, A Jupyter widget using sigma.js to render interactive networks. Zenodo.https://doi.org/10.5281/zenodo.7446059