.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/11_temporal/plot_38_evolving_narratives.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 or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_11_temporal_plot_38_evolving_narratives.py: Evolving narratives in a temporal hypergraph ============================================ The synthetic news hypergraph has three periods. Snapshot turnover, persistence of theme combinations, vertex activity over time and the frequent itemsets per period show how the narratives change — the questions that the hypergraph analysis of climate-change news coverage asks. .. GENERATED FROM PYTHON SOURCE LINES 12-29 .. code-block:: Python import matplotlib.pyplot as plt import pandas as pd import hatvis as hv from hatvis.plotting import plot_activity T = hv.datasets.make_news_transactions(150, random_state=0) # [snippet:temporal] print(hv.temporal.turnover(T)) print(hv.temporal.persistence(T).head(5).to_string()) top = {t: hv.frequent_itemsets(S, min_support=0.08, min_size=2).head(3) for t, S in T.snapshots().items()} # [/snippet:temporal] for t, fi in top.items(): print(t, [sorted(s) for s in fi["itemset"]]) share = pd.crosstab(T.edge_data["time"], T.edge_data["narrative"].str.contains("finance"), normalize="index") print("share of articles with the finance narrative:", share[True].round(3).to_dict()) .. rst-class:: sphx-glr-script-out .. code-block:: none from to new persisting dropped jaccard 0 2021 2022 94 29 86 0.138756 1 2022 2023 90 26 97 0.122066 members size occurrences first last 0 (AID, DEVELOPING, DROUGHT, FINANCE, FLOOD, HEATWAVE, LOSS_DAMAGE, WILDFIRE) 8 3 2021 2023 1 (AGREEMENT, AID, DEVELOPING, FINANCE, LOSS_DAMAGE, NEGOTIATION, SUMMIT) 7 3 2021 2023 2 (DROUGHT, FLOOD, HEATWAVE, WILDFIRE) 4 3 2021 2023 3 (HEALTH, MIGRATION, PROTEST, YOUTH) 4 3 2021 2023 4 (CLIMATE, EMISSIONS, IPCC, TEMPERATURE) 4 3 2021 2023 2021 [['EMISSIONS', 'TEMPERATURE'], ['COAL', 'OIL_GAS'], ['AGREEMENT', 'PLEDGE']] 2022 [['CLIMATE', 'EMISSIONS'], ['EMISSIONS', 'IPCC'], ['EMISSIONS', 'TEMPERATURE']] 2023 [['DEVELOPING', 'LOSS_DAMAGE'], ['AID', 'LOSS_DAMAGE'], ['DEVELOPING', 'FINANCE']] share of articles with the finance narrative: {'2021': 0.1, '2022': 0.187, '2023': 0.34} .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python fig, ax = plt.subplots(figsize=(7, 6)) plot_activity(T, ax=ax, title="theme activity per period") plt.tight_layout() .. image-sg:: /auto_examples/11_temporal/images/sphx_glr_plot_38_evolving_narratives_001.png :alt: theme activity per period :srcset: /auto_examples/11_temporal/images/sphx_glr_plot_38_evolving_narratives_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.312 seconds) .. _sphx_glr_download_auto_examples_11_temporal_plot_38_evolving_narratives.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/hatvis/main?urlpath=lab/tree/notebooks/auto_examples/11_temporal/plot_38_evolving_narratives.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_38_evolving_narratives.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_38_evolving_narratives.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_38_evolving_narratives.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_