question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

problem in plotting a network using `show`

See original GitHub issue

Hello @marcomusy

I’ve the following to plot a dataset using show

    data1 = dict(zip(time, df1.values.tolist()))

    data2 = dict(zip(time, df1.values.tolist()))



    ts = [0, 1, 2, 3]

    for t in ts:

        pts.cmap('Blues', data1[t], vmin=0, vmax=234)

        if t == 0.0:

            pts.addScalarBar()

            show(pts, edg, axes=True, bg='black', at=ts.index(t), shape=(2, len(ts)))

        else:

            show(pts, edg, axes=True, bg='black', at=ts.index(t))

        pts.cmap('Blues', data2[t], vmin=0, vmax=234)

        if t != ts[-1]:

            show(pts, edg, axes=True, bg='black', at=ts.index(t)+4)

        else:

            show(pts, edg, axes=True, bg='black', at=ts.index(t)+4, interactive=True)

The problem is, in the 2 x 4 grid that is created, the pts data is not appended to the frame while looping through t instead it is overwritten. i.e in the first row: the plot added at =0 in the first iteration is overwritten by the plot generated for displaying at=2 in the second iteration. The same problem occurs in the second row. The plot added at =1 in the first iteration is overwritten by the plot generated for displaying at=3 in the second iteration.

Suggestions on how to avoid overwriting will be helpful.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
marcomusycommented, Nov 8, 2020

This is one possibility, removing the separator frames:

import networkx as nx
from vedo import *

settings.showRendererFrame = False # disable grey frame

G = nx.gnm_random_graph(n=10, m=15, seed=1)
nxpos = nx.spring_layout(G)

nxpts = [nxpos[pt] for pt in sorted(nxpos)]
nx_lines = [(nxpts[i], nxpts[j]) for i, j in G.edges()]

pts = Points(nxpts, r=12)
edg = Lines(nx_lines).lw(2)

# node values
values = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
          [30, 80, 10, 79, 70, 60, 75, 78, 65, 10],
          [1, .30, .10, .79, .70, .60, .75, .78, .65, .90],
          ]
times = [0.0, 0.1, 0.2]  # in seconds

vmin, vmax = min(utils.flatten(values)), max(utils.flatten(values))
x0,x1, y0,y1, z0,z1 = pts.bounds()

plt = Plotter(shape=(1,3), axes=True, bg='black')

for i,t in enumerate(times):
    pts1 = pts.clone().cmap('Blues', values[i], vmin=vmin, vmax=vmax)
    txt = Text('time = '+str(t)+'s', font='BPmonoItalics',
               justify='bottom-center', s=.07, c='lb')
    txt.pos((x0+x1)/2, y1+0.2)
    box = txt.box(pad=0.1).scale([1,1,0])
    if i==2:
        pts1.addScalarBar3D(c='w')
        pts1.scalarbar.scale(1.2)
    plt.show(pts1, edg, txt, box, at=i)

interactive()

image

I updated the code with a better solution probably!

1reaction
marcomusycommented, Aug 3, 2020

that’s correct… because you are plotting the same object onto different renderers but then you change its colors… Make a clone copy instead, and change the copy: pts2 = pts.clone().cmap('Blues', values[1])

Read more comments on GitHub >

github_iconTop Results From Across the Web

networking - How to fix nodes when plotting a subset over a ...
My target is to overlay both networks, so that one can see the complete network netX in the background and the subset netY...
Read more >
Network visualization with R
In this tutorial, we will work primarily with two small example data sets. Both contain data about media organizations. One involves a network...
Read more >
Python | Visualize graphs generated in NetworkX using ...
In this article, we will be discussing how to plot a graph generated by NetworkX in Python using Matplotlib. NetworkX is not a...
Read more >
5.4 Plotting the network in igraph - George G. Vega Yon
5.4.1 Single plot. Let's take a look at how does our network looks like when we use the default parameters in the plot...
Read more >
"This plotter configuration cannot be used..." when plotting ...
This warning appears because the plot configuration referenced by the drawing has one or more of the following problems:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found