.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/other/plot_graph.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_other_plot_graph.py: Charts as graph visualisations ============================== This example shows how to use ``iplotx`` to display changes of a quantity over time. This is a kind of chart that would not usually be considered a graph, but can be reinterpreted that way to make use of ``iplotx``'s visual capabilities. .. GENERATED FROM PYTHON SOURCE LINES 9-39 .. code-block:: Python import datetime import networkx as nx import matplotlib.pyplot as plt import iplotx as ipx times = ["2021-01-01", "2021-02-01", "2021-03-01", "2021-04-01", "2021-05-01"] quantity = [10, 15, 7, 20, 12] # Convert the date strings to numbers because iplotx does not understand dates dates = [datetime.datetime(*list(map(int, t.split("-")))) for t in times] days_since_start = [(d - dates[0]).days for d in dates] g = nx.path_graph(len(quantity), create_using=nx.DiGraph) layout = {i: (days_since_start[i], quantity[i]) for i in range(len(quantity))} fig, ax = plt.subplots() ipx.network( g, layout, ax=ax, strip_axes=False, zorder=2, ) ax.set_xticks(days_since_start) ax.set_xticklabels(times, rotation=45, ha="right") ax.set_ylabel("Quantity") ax.grid(True) fig.tight_layout() .. image-sg:: /gallery/other/images/sphx_glr_plot_graph_001.png :alt: plot graph :srcset: /gallery/other/images/sphx_glr_plot_graph_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 40-41 This can also be done in another way by using a single edge: .. GENERATED FROM PYTHON SOURCE LINES 41-61 .. code-block:: Python g = nx.DiGraph([(0, 4)]) fig, ax = plt.subplots() ipx.network( g, layout, ax=ax, strip_axes=False, zorder=2, edge_waypoints=[[ layout[1], layout[2], layout[3], ]], ) ax.set_xticks(days_since_start) ax.set_xticklabels(times, rotation=45, ha="right") ax.set_ylabel("Quantity") ax.grid(True) fig.tight_layout() .. image-sg:: /gallery/other/images/sphx_glr_plot_graph_002.png :alt: plot graph :srcset: /gallery/other/images/sphx_glr_plot_graph_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.153 seconds) .. _sphx_glr_download_gallery_other_plot_graph.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_graph.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_graph.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_graph.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_