Skip to content

Latest commit

 

History

History
314 lines (206 loc) · 6.46 KB

examples.rst

File metadata and controls

314 lines (206 loc) · 6.46 KB
%load_ext cypher
%config CypherMagic
CypherMagic options
-----------------
CypherMagic.auto_html=<Bool>
    Current: False
    Return a D3 representation of the graph instead of regular result sets
CypherMagic.auto_limit=<Int>
    Current: 0
    Automatically limit the size of the returned result sets
CypherMagic.auto_networkx=<Bool>
    Current: False
    Return Networkx MultiDiGraph instead of regular result sets
CypherMagic.auto_pandas=<Bool>
    Current: False
    Return Pandas DataFrame instead of regular result sets
CypherMagic.data_contents=<Bool>
    Current: True
    Bring extra data to render the results as a graph
CypherMagic.display_limit=<Int>
    Current: 0
    Automatically limit the number of rows displayed (full result set is still
    stored)
CypherMagic.feedback=<Bool>
    Current: True
    Print number of rows affected
CypherMagic.rest=<Bool>
    Current: False
    Return full REST representations of objects inside the result sets
CypherMagic.short_errors=<Bool>
    Current: True
    Don't display the full traceback on Neo4j errors
CypherMagic.style=<Unicode>
    Current: u'DEFAULT'
    Set the table printing style to any of prettytable's defined styles
    (currently DEFAULT, MSWORD_FRIENDLY, PLAIN_COLUMNS, RANDOM)
%cypher optional match (n)-[r]-() delete n, r
6 relationship deleted.
6 nodes deleted.
[]
%%cypher
create
    // Nodes
    (Neo:Crew {name:'Neo'}),
    (Morpheus:Crew {name: 'Morpheus'}),
    (Trinity:Crew {name: 'Trinity'}),
    (Cypher:Crew:Matrix {name: 'Cypher'}),
    (Smith:Matrix {name: 'Agent Smith'}),
    (Architect:Matrix {name:'The Architect'}),
    // Relationships
    (Neo)-[:KNOWS]->(Morpheus),
    (Neo)-[:LOVES]->(Trinity),
    (Morpheus)-[:KNOWS]->(Trinity),
    (Morpheus)-[:KNOWS]->(Cypher),
    (Cypher)-[:KNOWS]->(Smith),
    (Smith)-[:CODED_BY]->(Architect);
7 labels added.
6 nodes created.
6 properties set.
6 relationships created.
[]
%cypher match (n)-[r]-() return n, count(r) as degree order by degree desc
6 rows affected.
n degree
{u'name': u'Morpheus'} 3
{u'name': u'Cypher'} 2
{u'name': u'Neo'} 2
{u'name': u'Trinity'} 2
{u'name': u'Agent Smith'} 2
{u'name': u'The Architect'} 1
%matplotlib inline
results = %cypher match (n)-[r]-() return n.name as name, count(r) as degree order by degree desc
results.dataframe()
6 rows affected.
name degree
0 Morpheus 3
1 Trinity 2
2 Agent Smith 2
3 Neo 2
4 Cypher 2
5 The Architect 1
results.plot()
[<matplotlib.lines.Line2D at 0x7f23e3e72950>]

examples_files/examples_7_1.png

results.bar()
<Container object of 6 artists>

examples_files/examples_8_1.png

results.pie()
([<matplotlib.patches.Wedge at 0x7f23e3c98f90>,
  <matplotlib.patches.Wedge at 0x7f23e3ca69d0>,
  <matplotlib.patches.Wedge at 0x7f23e3cb2390>,
  <matplotlib.patches.Wedge at 0x7f23e3cb2d10>,
  <matplotlib.patches.Wedge at 0x7f23e3cbe6d0>,
  <matplotlib.patches.Wedge at 0x7f23e3ccb090>],
 [<matplotlib.text.Text at 0x7f23e3ca6590>,
  <matplotlib.text.Text at 0x7f23e3ca6f90>,
  <matplotlib.text.Text at 0x7f23e3cb2950>,
  <matplotlib.text.Text at 0x7f23e3cbe310>,
  <matplotlib.text.Text at 0x7f23e3cbec90>,
  <matplotlib.text.Text at 0x7f23e3ccb650>])

examples_files/examples_9_1.png

for i in range(1, 5):
    %cypher match (n) return n, n.name limit {i}
1 rows affected.
2 rows affected.
3 rows affected.
4 rows affected.
results = %cypher match (n)-[r]-() return n.name as name, n, r, count(r) as degree order by degree desc
12 rows affected.
results.draw()
(<networkx.classes.multidigraph.MultiDiGraph at 0x7f23e3c5a510>,
 <matplotlib.axes._subplots.AxesSubplot at 0x7f23e3ccba90>,
 <matplotlib.collections.PathCollection at 0x7f23e3c06050>)
/home/versae/.venvs/ipython-cypher/local/lib/python2.7/site-packages/matplotlib/text.py:52: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if rotation in ('horizontal', None):
/home/versae/.venvs/ipython-cypher/local/lib/python2.7/site-packages/matplotlib/text.py:54: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif rotation == 'vertical':

examples_files/examples_12_2.png