Skip to content
Snippets Groups Projects
Commit 6917cebc authored by felix's avatar felix
Browse files

update colorscale on edges

parent 94cfb8ac
No related branches found
No related tags found
No related merge requests found
......@@ -331,20 +331,29 @@ class flow_circuit(circuit,object):
self.init_plexus_default()
# output
def get_nodes_data(self):
def get_nodes_data(self,*args ):
dn=pd.DataFrame(self.nodes[['source','label']])
# dn=pd.DataFrame(self.nodes[['source','label']])
cols=['label','source']
cols+=[a for a in args if a in self.nodes.columns]
dn=pd.DataFrame(self.nodes[cols])
return dn
def get_edges_data(self,**kwargs):
def get_edges_data(self,*args ):
de=pd.DataFrame(self.edges[['conductivity','flow_rate']])
# de=pd.DataFrame(self.edges[['conductivity','flow_rate']])
if 'width' in kwargs:
de['weight']=np.absolute(self.edges[kwargs['width']].to_numpy())*self.draw_weight_scaling
else:
de['weight']=np.power(self.edges['conductivity'].to_numpy(),0.25)*self.draw_weight_scaling
# if 'width' in kwargs:
# de['weight']=np.absolute(self.edges[kwargs['width']].to_numpy())*self.draw_weight_scaling
# else:
# de['weight']=np.power(self.edges['conductivity'].to_numpy(),0.25)*self.draw_weight_scaling
cols=['label','conductivity','flow_rate']
cols+=[a for a in args if a in self.edges.columns]
de=pd.DataFrame(self.edges[cols])
# if 'color_edges' in pars:
# de['color_edges']=np.absolute(self.edges[pars['color']].to_numpy())
......@@ -353,12 +362,12 @@ class flow_circuit(circuit,object):
return de
def plot_circuit(self, **kwargs):
E=self.get_edges_data(**kwargs)
V=self.get_nodes_data()
def plot_circuit(self,*args, **kwargs):
self.set_pos()
fig=dx.plot_networkx( self.G, edge_list=self.list_graph_edges, node_list=self.list_graph_nodes, edge_data=E, node_data=V )
E=self.get_edges_data(*args)
V=self.get_nodes_data(*args)
fig=dx.plot_networkx( self.G, edge_list=self.list_graph_edges, node_list=self.list_graph_nodes, edge_data=E, node_data=V ,**kwargs)
return fig
......@@ -10,8 +10,10 @@
import networkx as nx
import numpy as np
import pandas as pd
import plotly
import plotly.graph_objects as go
#generate interactive plots with plotly and return the respective figures
def plot_networkx(input_graph,**kwargs):
......@@ -19,7 +21,8 @@ def plot_networkx(input_graph,**kwargs):
'network_id':0,
'color_nodes':['#a845b5'],
'color_edges':['#c762d4'],
'markersize': [2]
'markersize': [2],
'linewidth': [5]
}
node_data=pd.DataFrame()
......@@ -49,7 +52,8 @@ def plot_networkx_dual(dual_graph,**kwargs):
'network_id':0,
'color_nodes':['#6aa84f','#a845b5'],
'color_edges':['#2BDF94','#c762d4'],
'markersize': [2,2]
'markersize': [2,2],
'linewidth': [5,5]
}
for k,v in kwargs.items():
......@@ -77,7 +81,7 @@ def add_traces_edges(fig, options, input_graph,extra_data):
idx=options['network_id']
edge_mid_trace=get_edge_mid_trace(input_graph,extra_data,color=options['color_edges'][idx])
edge_invd_traces=get_edge_invd_traces(input_graph,extra_data,color=options['color_edges'][idx])
edge_invd_traces=get_edge_invd_traces(input_graph,extra_data,color=options['color_edges'][idx], linewidth= options['linewidth'][idx])
for eit in edge_invd_traces:
fig.add_trace(eit)
......@@ -187,12 +191,13 @@ def get_edge_invd_traces(input_graph,extra_data, **kwargs):
options[k]=v
# handle exceptions and new containers
colorful=False
if type(options['color'])!=str:
colorful=True
options['colorscale']='plasma'
options['cmin']=np.min(options['color'])
options['cmax']=np.max(options['color'])
cmax=np.max(options['color'])
cmin=np.min(options['color'])
options['color']= plotly.colors.sample_colorscale('plasma', options['color'], low=cmin, high=cmax)
pos=nx.get_node_attributes(input_graph,'pos')
if len(list(pos.values())[0]) != dim:
......@@ -208,14 +213,14 @@ def get_edge_invd_traces(input_graph,extra_data, **kwargs):
aux_option=dict(options)
for i,edge in enumerate(E):
aux_option['width']=5.
# aux_option['width']=options['linewidth']
aux_option['width']=2
if 'weight' in extra_data:
aux_option['width']=extra_data['weight'][i]
if colorful:
aux_option['color']=[options['color'][i] for j in range(2)]
aux_option['color']=options['color'][i]
trace=get_line_from_template(dim,aux_option)
XYZ_0 = input_graph.nodes[edge[0]]['pos']
......
......@@ -12,8 +12,8 @@ with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setuptools.setup(
name="kirchhoff",
version="0.1.8",
name="kirchhoff",
version="0.1.9",
author="felixk1990",
author_email="felixuwekramer@protonmail.com",
description="Collection of routines for creation and manipulation of Kirchhoff circuits based on resistor-only networks, together with 2D/3D spatial embeddings. ",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment