beeware / beeware/toga-chart

Providing Example for networkx

Open
#80 1 comment 0 reactions 0 assignees View on GitHub
documentation
Dominant language
Python
Stars
30
Forks
22
Avg merge
3h 50m
Merged PRs (30d)
2

Description

### What is the problem or limitation you are having?

Networkx is a powerful tool in data analysis, would be nice to see an example

### Describe the solution you'd like

I'm providing code here for a basic example. It should be pointed out that most networkx examples rely on the `plot.show()` command which does not appear to be available in toga-chart. So you have to do the drawing yourself. That's okay, networks still provides the layout.

```
"""This is where the chart is created"""
def draw_chart(self, chart, figure, *args, **kwargs):
# The Karate Club example is built into nx
G = nx.karate_club_graph()
ax = figure.add_subplot(1, 1, 1)
ax.set_axis_off()
pos = nx.circular_layout(G)
# Spring is a more popular layout, but circular is easier to debug
#pos = nx.spring_layout(G)
x = [k[0] for k in pos.values()]
y = [k[1] for k in pos.values()]
for e in G.edges():
# Note, this takes a sequence of xs, then ys. That took a while!
p1 = [x[e[0]], x[e[1]]]
p2 = [y[e[0]], y[e[1]]]
ax.plot(p1, p2, marker='o', linestyle='-', color='r')
```

### Describe alternatives you've considered

Tried matplotlib directly.

### Additional context

Hoping this is useful to someone.

Contributor guide

Open the contributing guide

Research direction

No file, test, or documentation entry point is named. Start by reviewing the existing toga-chart examples and documentation, then assess where the supplied Karate Club network example belongs. Done means the example is added in the appropriate location and explains the manual drawing approach without relying on plot.show().

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, python
Domain
data-visualization, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.