Is dropping an edge property expected to drop its edge? - datastax-startup

With DSE v5.0.3, I've encountered a situation where dropping an edge property drops its edge as well.
Both of the gremlin console examples use the following schema configuration:
gremlin> system.graph('example').create()
==>null
gremlin> :remote config alias g example.g
==>g=example.g
gremlin> schema.propertyKey('notes').Text().single().create()
==>null
gremlin> schema.vertexLabel('person').create()
==>null
gremlin> schema.edgeLabel('knows').properties('notes').create()
==>null
gremlin> schema.edgeLabel('knows').connection('person', 'person').add()
==>null
In the following example, dropping the edge property results in the edge itself being dropped:
gremlin> person1 = g.addV('person').next()
==>v[{~label=person, community_id=1566048896, member_id=0}]
gremlin> person2 = g.addV('person').next()
==>v[{~label=person, community_id=1062113536, member_id=0}]
gremlin> knows = g.V(person1).addE('knows').to(V(person2)).property('notes', 'online').next()
==>e[{~type=knows, out_vertex={~label=person, community_id=1566048896, member_id=0}, in_vertex={~label=person, community_id=1062113536, member_id=0}, local_id=4cd8f8e2-a6b8-11e6-aa90-df2b21a156a2}][{~label=person, community_id=1566048896, member_id=0}-knows->{~label=person, community_id=1062113536, member_id=0}]
gremlin> g.E(knows)
==>e[{~type=knows, out_vertex={~label=person, community_id=1566048896, member_id=0}, in_vertex={~label=person, community_id=1062113536, member_id=0}, local_id=4cd8f8e2-a6b8-11e6-aa90-df2b21a156a2}][{~label=person, community_id=1566048896, member_id=0}-knows->{~label=person, community_id=1062113536, member_id=0}]
gremlin> g.E(knows).properties('notes')
==>p[notes->online]
gremlin> g.E(knows).properties('notes').drop()
gremlin> g.E(knows)
gremlin>
This next example creates the same set of data, but instead of setting the 'notes' property in the same traversal as the addE step, it creates the property in a separate traversal. Unlike in the example above, dropping the 'notes' property drops the property while leaving the edge intact.
gremlin> person1 = g.addV('person').next()
==>v[{~label=person, community_id=1437137920, member_id=0}]
gremlin> person2 = g.addV('person').next()
==>v[{~label=person, community_id=1317720192, member_id=0}]
gremlin> knows = g.V(person1).addE('knows').to(V(person2)).next()
==>e[{~type=knows, out_vertex={~label=person, community_id=1437137920, member_id=0}, in_vertex={~label=person, community_id=1317720192, member_id=0}, local_id=847ebaf0-a6b8-11e6-aa90-df2b21a156a2}][{~label=person, community_id=1437137920, member_id=0}-knows->{~label=person, community_id=1317720192, member_id=0}]
gremlin> g.E(knows).property('notes', 'online')
==>e[{~type=knows, out_vertex={~label=person, community_id=1437137920, member_id=0}, in_vertex={~label=person, community_id=1317720192, member_id=0}, local_id=847ebaf0-a6b8-11e6-aa90-df2b21a156a2}][{~label=person, community_id=1437137920, member_id=0}-knows->{~label=person, community_id=1317720192, member_id=0}]
gremlin> g.E(knows).properties()
==>p[notes->online]
gremlin> g.E(knows).properties('notes').drop()
gremlin> g.E(knows)
==>e[{~type=knows, out_vertex={~label=person, community_id=1437137920, member_id=0}, in_vertex={~label=person, community_id=1317720192, member_id=0}, local_id=847ebaf0-a6b8-11e6-aa90-df2b21a156a2}][{~label=person, community_id=1437137920, member_id=0}-knows->{~label=person, community_id=1317720192, member_id=0}]
gremlin> g.E(knows).properties()
gremlin>

Thank you for the feedback Leifur. This appears to be a bug and we've filed an internal JIRA and the engineering team is investigating.

Related

Networkx Edge Colormap Based on Attribute

I have a graph where each edge (not nodes) has a capacity and a load. I want to draw this graph using a color map which is a gradient from blue to red, red being the most loaded and blue being the less loaded. I tried to understand the official documentation of Edge Colormap, but it doesn't help me. Can you help me?
The key is to set edge_color to be a sequence of edges coinciding with edgelist, both keyword arguments of nx.draw_networkx. Here is a minimal working example using pandas and networkx.
import networkx as nx
import pandas as pd
edge_df = pd.DataFrame({"source": [0, 1, 2],
"target": [1, 2, 0],
"capacity": [.1, .2, .3],
"load": [40, 20, 10]})
G = nx.from_pandas_edgelist(edge_df,
source="source",
target="target",
edge_attr=["capacity", "load"])
nx.draw_networkx(G,
edgelist=list(zip(edge_df['source'], edge_df['target'])),
edge_color=edge_df['capacity'],
edge_cmap=plt.cm.bwr)
Should get you something like this:

Networkx visualization

I am new to netwrokx and I have a big network as follows that I need to just visualize its blue nodes:
Is there any way to see just blue nodes while the distance between them is same as the real graph's?
My desired output would be something like following one:
Result of using pos layout is as follows:
Joel helped med to find out the result and I share codes and outcome here for those who have the similar question:
Answer Codes:
pos = nx.spring_layout(G)
nx.draw_networkx(G, pos, nodelist = blue_nodes, node_color =
'blue',with_labels=False)
outcome:
Given a network G, with a list of "blue" nodes bluenodes, we can define a set of positions, and then draw just the blue nodes.
pos = nx.spring_layout(G) #there are other layouts that you might want to try.
nx.draw_networkx_nodes(G, pos, nodelist = bluenodes, node_color = 'blue', with_labels=False)

how to generate a heatmap in ipyleaflet

I have multiple coordinates (latitude and longitude) and I would like to create a heatmap. I have checked all the documentation online and examples and cannot find anything which helps my to create a heatmap on an ipyleaflet map.
Please could someone advise how I generate and add a heatmap layer onto an ipyleaflet map.
I am working inside a jupyter notebook.
Thanks
Since the last version of ipyleaflet it is now possible to create a HeatMap:
from ipyleaflet import Map, Heatmap
from random import uniform
m = Map(center=[0, 0], zoom=2)
locations = [
[uniform(-80, 80), uniform(-180, 180), uniform(0, 1000)] # lat, lng, intensity
for i in range(1000)
]
heat = Heatmap(locations=locations, radius=20, blur=10)
m.add_layer(heat)
# Change some attributes of the heatmap
heat.radius = 30
heat.blur = 50
heat.max = 0.5
heat.gradient = {0.4: 'red', 0.6: 'yellow', 0.7: 'lime', 0.8: 'cyan', 1.0: 'blue'}
m

How to remove edge between two vertices?

I want to remove edge between two vertices, so my code in java tinkerpop3 as below
private void removeEdgeOfTwoVertices(Vertex fromV, Vertex toV,String edgeLabel,GraphTraversalSource g){
if(g.V(toV).inE(edgeLabel).bothV().hasId(fromV.id()).hasNext()){
List<Edge> edgeList = g.V(toV).inE(edgeLabel).toList();
for (Edge edge:edgeList){
if(edge.outVertex().id().equals(fromV.id())) {
TitanGraph().tx();
edge.remove();
TitanGraph().tx().commit();
return;//Remove edge ok, now return.
}
}
}
}
Is there a simpler way to remove edge between two vertices by a direct query to that edge and remove it? Thank for your help.
Here's an example of how to drop edges between two vertices (where you just have the ids of those vertices:
gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V(1).bothE()
==>e[9][1-created->3]
==>e[7][1-knows->2]
==>e[8][1-knows->4]
For purpose of the example, let's say we want to drop edges between vertex 1 and vertex 2. We could find those with:
gremlin> g.V(1).bothE().where(otherV().hasId(2))
==>e[7][1-knows->2]
and then remove it with:
gremlin> g.V(1).bothE().where(otherV().hasId(2)).drop()
gremlin> g.V(1).bothE()
==>e[9][1-created->3]
==>e[8][1-knows->4]
If you have the actual vertices, then you could just do:
gremlin> g.V(v1).bothE().where(otherV().is(v2)).drop()
gremlin> g.V(1).bothE()
==>e[9][1-created->3]
==>e[8][1-knows->4]
You could re-write your function as:
private void removeEdgeOfTwoVertices(Vertex fromV, Vertex toV,String edgeLabel,GraphTraversalSource g){
g.V(fromV).bothE().hasLabel(edgeLabel).where(__.otherV().is(toV)).drop().iterate();
g.tx().commit();
}

3D image plotting

I am facing a problem doing some animation for a assignment in matlab
Let say that for instance I have a matrix 3D where the last index determine the color and the the others are determining the x,y,z coordinates.
a(:,:,1,1) =
0.9124 0.8790 0.8823
0.3242 0.7791 0.4257
0.2905 0.3944 0.4664
a(:,:,2,1) =
0.4249 0.0956 0.4965
0.4552 0.7335 0.2597
0.6954 0.1300 0.5917
a(:,:,3,1) =
0.2276 0.1832 0.1372
0.9551 0.6242 0.1889
0.0630 0.2914 0.9566
a(:,:,1,2) =
0.2966 0.0043 0.2240
0.2372 0.0782 0.6953
0.6602 0.3096 0.7002
a(:,:,2,2) =
0.8518 0.5309 0.3834
0.5591 0.8589 0.5954
0.5703 0.4463 0.3050
a(:,:,3,2) =
0.1011 0.6432 0.6211
0.3719 0.7767 0.2791
0.2222 0.4300 0.4780
a(:,:,1,3) =
0.3147 0.1443 0.7440
0.8272 0.0683 0.8357
0.7432 0.5321 0.7207
a(:,:,2,3) =
0.8876 0.8820 0.7249
0.1629 0.4620 0.8836
0.2012 0.1870 0.7980
a(:,:,3,3) =
0.8430 0.5304 0.7167
0.5380 0.8433 0.8627
0.2096 0.2153 0.4713
Now I need a 3D image where all the point should be like the result we get when we use imagesc matlab command.
To display slice #3 (z=3):
zind = 3;
imagesc(squeeze(a(:,:,zind,:)))