oemof / oemof-tabular

Load oemof energy systems from tabular data sources.
https://oemof-tabular.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
7 stars 5 forks source link

Install pygraphviz fails #168

Open nailend opened 8 months ago

nailend commented 8 months ago
z/graphviz_wrap.c -o build/temp.linux-x86_64-cpython-310/pygraphviz/graphviz_wrap.o
      pygraphviz/graphviz_wrap.c:3020:10: fatal error: graphviz/cgraph.h: No such file or directory
       3020 | #include "graphviz/cgraph.h"
            |          ^~~~~~~~~~~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pygraphviz
Failed to build pygraphviz

Install this: sudo apt-get install python3-dev graphviz libgraphviz-dev pkg-config and then pip install pygraphviz in your environment source

nailend commented 8 months ago

@SabineHaas In case you want to plot graphs with pygraphviz

e.g. BEV component

def draw_graph(energysystem):
    # Draw the graph

    from oemof.network.graph import create_nx_graph

    G = create_nx_graph(energysystem)

    # Specify layout and draw the graph
    pos = nx.drawing.nx_agraph.graphviz_layout(
        G, prog="neato", args="-Gepsilon=0.0001"
    )

    fig, ax = plt.subplots(figsize=(10, 8))
    node_colors = list()
    for i in list(G.nodes()):
        if "storage" in i:
            node_colors.append("royalblue")
        elif "BEV-V2G" in i:
            node_colors.append("firebrick")
        elif "BEV-G2V" in i:
            node_colors.append("lightblue")
        elif "BEV-inflex" in i:
            node_colors.append("darkviolet")
        elif "excess" in i:
            node_colors.append("green")
        elif "shortage" in i:
            node_colors.append("yellow")
        elif "load" in i:
            node_colors.append("orange")
        elif "wind" in i:
            node_colors.append("pink")
        elif "bus" in i:
            node_colors.append("grey")
        else:
            node_colors.append("violet")

    nx.draw(
        G,
        pos,
        # **options,
        with_labels=True,
        node_size=3000,
        # node_color='lightblue',
        font_size=10,
        font_weight="bold",
        node_color=node_colors,
        # node_color=["red", "blue", "green", "yellow", "orange"],
    )
    labels = nx.get_edge_attributes(G, "weight")
    nx.draw_networkx_edge_labels(G, pos=pos, edge_labels=labels)

    # Customize the plot as needed
    ax.set_title("OEMOF Energy System Graph")

    # Show the plot
    plt.show()