Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing Example for networkx #80

Open
buddha314 opened this issue Jan 7, 2024 · 1 comment
Open

Providing Example for networkx #80

buddha314 opened this issue Jan 7, 2024 · 1 comment
Labels
documentation An improvement required in the project's documentation.

Comments

@buddha314
Copy link

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.

@buddha314 buddha314 added the enhancement New features, or improvements to existing features. label Jan 7, 2024
@freakboy3742 freakboy3742 added documentation An improvement required in the project's documentation. and removed enhancement New features, or improvements to existing features. labels Jan 7, 2024
@freakboy3742
Copy link
Member

Thanks for the suggestion. I don't want Toga-chart's documentation to become a reproduction of all of Matplotlib's documentation (or an attempt at a replacement for Matplotlib's documentation) - but a couple of examples showing how Matplotlib code maps to Toga-chart is definitely called for - especially when it comes to core usage issues like the fact that plot.show() isn't explicitly needed. Tagging as a documentation ticket on that basis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation An improvement required in the project's documentation.
Projects
None yet
Development

No branches or pull requests

2 participants