How to use TinkerPop to print out an image? - neo4j

For example, given this graph:
gremlin> graph = TinkerFactory.createModern() (1)
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal(standard()) (2)
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().has('name','marko').out('knows').values('name') (3)
I want to print out a PNG file for this graph from the console. The documentation doesn't say how to do it. Thanks in advance.

TinkerPop doesn't provide graph visualization options directly. The best you can do is either:
Use the Gephi plugin to visualize your graph and then save that visualization to an image.
Export your graph to GraphML and then import it into a visualization tool, like Gephi, Cytoscape, etc. and then export an image generated from there.

If you use Python at all, the networkx and matploitlib libraries can read a GraphML file and render it. I have used this in a Python Notebook with Gremlin Python running where I extracted a subgraph to GraphML and rendered it using Python.
The code would be along the lines of:
import matplotlib
import matplotlib.pyplot as plt
import networkx as nx
G = nx.parse_graphml(mygraph)
label = nx.get_node_attributes(G, "code")
plt.figure(figsize=(11,11))
nx.draw(G, node_color="#ffaa00",node_size=1200,labels=label,arrows=False)
Apologies in advance if my Python is ugly I'm more of a Ruby and Groovy guy :-)

Related

how to upload report with graph and comments from jupyter notebook in Google Spreadsheet

I have some report, here is a sample to repeat:
In[1]:import pandas as pd
import numpy as np
In[2]:import seaborn as sns
sns.set_theme(style="darkgrid")
# Load an example dataset with long-form data
fmri = sns.load_dataset("fmri")
# Plot the responses for different events and regions
sns.lineplot(x="timepoint", y="signal",
hue="region", style="event",
data=fmri)
Out[2]:
In[3]:fmri
Out[3]:
How can I upload my report from jupyter notebook to google sheets, because I have a task to hand over the work in the file "https://docs.google.com/spreadsheets/...." but there were no restrictions on what is better to do, I saw this only when I tried to upload a link to my github in the google form, now I think how can I convert my results, one of the options is to insert screenshots of my report into a file in google sheets, but maybe there is a better option

can't show an image using PIL on google colab

I am trying to use PIL to show an image. I know that I can use other modules to do that. I am working on google colab. But I can't figure out why PIL is not showing output image.
% matplotlib inline
import numpy as np
import PIL
im=Image.open('/content/drive/My Drive/images-process.jpeg')
print(im.width, im.height, im.mode, im.format, type(im))
im.show()
output: 739 415 RGB JPEG < class 'PIL.JpegImagePlugin.JpegImageFile'>
Instead of
im.show()
Try just
im
Colab should try to display it on its own. See example notebook
Use
display(im)
instead of im.show() or im.
When using these options after multiple lines or in a loop, im won't work.
After you open an image(which you have done using Image.open()), try converting using im.convert() to which ever mode image is in then do display(im)
It will work

Tooltip on bokeh violin chart built from seaborn package

I was trying to use violin chart in Bokeh but unable to find this type of chart. So, I use seaborn library to build the violin chart and use it into bokeh.
Code:
import seaborn as sns
from bokeh import mpl
import pandas as pd
df = pd.DataFrame({"x": [1,1,1,2], "y":4,5,8,9})
sns.violinplot(x="x", y="y", data=df)
plot = mpl.to_bokeh()
plot.plot_width = 500
plot.plot_height = 300
Now, I want to add tooltip on bokeh converted chart from seaborn. I googled a lot but not able to find a way.
This is no longer possible, at least in this form. The MPL compatibilityin bokeh, including mpl.to_bokeh() was deprecated and completely removed some time ago. You might have a look at Holoviews which is a very high level API built on top of Bokeh that I believe just added a Violin plot.

saving figures seaborn to sageplot

I have been trying to save statistical graphs (boxplot, barchart, histogram etc) of some random data generated using Seaborn into LaTeX without saving them into a file first. I use \sageplot[width=8cm][png]{(Python_Graphics_Format)} from SageTex package to do this.
For example, when I draw a Box Plot using Seaborn it generates all kinds of format (name.gcf(), name.show(), name.plot(), name.draw() etc) but Graphics format. Is there any way to do this without using 'name.savefig()' or likes?
Why is it important for me?
I would like to generate a list of predefined sage functions in a separate tex file together with bunch of randomly generated data and input them on top of my TeX code after \maketitle. This way, I will be able to generate multiple problems of similar nature and upload them to the online HW system Ximera.
Here is a code that I took from stackoverflow:
import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.boxplot(x=tips["total_bill"])
Your help is most appreciated.

py2neo: minimizing write-time when creating graph

I would write a huge graph to neo4j. Using my code would take slightly less than two months.
I took the data from Kaggle's events recommendation challenge, the user_friends.csv file I am using looks like
user,friends
3197468391,1346449342 3873244116 4226080662, ...
I used the py2neo batch facility to produce the code. Is it the best I can do or is there another way to significantly reduce the running time?
Here 's the code
#!/usr/bin/env python
from __future__ import division
from time import time
import sqlite3
from py2neo import neo4j
graph = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
batch = neo4j.WriteBatch(graph)
people = graph.get_or_create_index( neo4j.Node,"people")
friends = graph.get_or_create_index( neo4j.Relationship,"friends")
con = sqlite3.connect("test.db")
c = con.cursor()
c.execute("SELECT user, friends FROM user_friends LIMIT 2;")
t=time()
for u_f in c:
u_node = graph.get_or_create_indexed_node("people",'name',u_f[0])
for f in u_f[1].split(" "):
f_node = graph.get_or_create_indexed_node("people",'name', f)
if not f_node.is_related_to(u_node, neo4j.Direction.BOTH,"friends"):
batch.create((u_node,'friends',f_node))
batch.submit()
print time()-t
Also I cannot find a way to create an undirected graph using the high level py2neo facilities? I knowcypher can do this with someting like create (node(1) -[:friends]-node(2))
Thanks in advance.
YOu should create connections not with Direction.BOTH. Chose one direction, and then ignore using Direction.BOTH it when traversing - it has no performance impact but the relationship directions are then deterministic. Cypher does exactly that when you say a--b.

Resources