.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/plotly/plot_main10_weather.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr__examples_plotly_plot_main10_weather.py: 10. Plot sparklines with weather ====================================== .. GENERATED FROM PYTHON SOURCE LINES 6-101 .. raw:: html :file: images/sphx_glr_plot_main10_weather_001.html .. code-block:: default :lineno-start: 6 # ------------------- # Main # ------------------- # https://chart-studio.plotly.com/~empet/13748/sparklines/#/code # https://omnipotent.net/jquery.sparkline/#s-about # https://chart-studio.plotly.com/create/?fid=Dreamshot:8025#/ # Libraries import glob import numpy as np import pandas as pd import plotly.express as px import plotly.graph_objects as go from pandas.tseries.offsets import DateOffset from plotly.subplots import make_subplots from plotly.io import show try: __file__ TERMINAL = True except: TERMINAL = False # Constants colors = px.colors.sequential.Viridis_r colors += px.colors.sequential.Viridis_r # ------------------- # Load data # ------------------- # Define folder folder = '../../datasets/weather-hmc-dataset/' # Load data data = pd.concat([pd.read_csv(f) \ for f in glob.glob('%s/*.csv' % folder)]) # Drop duplicates data = data.drop_duplicates() data['dates'] = pd.to_datetime(data['Date time']) data = data.set_index('dates') data = data.drop(columns=['Name', 'Date time', 'Conditions']) if TERMINAL: print("\nData:") print(data) data # ---------------- # Visualize # ---------------- # Create layout layout = { "font": {"family": "Georgia, serif"}, "title": "Weather Ho Chi Minh", #"width": 500, "height": 1000, #"margin": {"t": 80}, "paper_bgcolor": 'rgba(0,0,0,0)', # transparent "plot_bgcolor": 'rgba(0,0,0,0)', # transparent #"autosize": False, "hovermode": "closest", "showlegend": False, } # Create figure fig = make_subplots(rows=data.shape[1], cols=1, shared_xaxes=True, subplot_titles=[t for t in data.columns]) # Add traces for i, column in enumerate(data.columns): # Colors c = colors[i] x = data.index y = data[column] # Add trace fig.add_trace(go.Scatter(x=x, y=y, name=column, mode='lines', fill='tozeroy', line=dict(color=c, width=0.5)), row=i+1, col=1) # Update axes fig.update_yaxes(title_text='', row=i+1, col=1) # Update layout fig.update_layout(layout) # Show show(fig) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 5.910 seconds) .. _sphx_glr_download__examples_plotly_plot_main10_weather.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_main10_weather.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_main10_weather.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_