<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Archives des graph | dash-resources.com</title>
	<atom:link href="https://dash-resources.com/tag/graph/feed/" rel="self" type="application/rss+xml" />
	<link>https://dash-resources.com/tag/graph/</link>
	<description>Learn to build interactive web applications with Python and Dash plotly</description>
	<lastBuildDate>Sat, 08 Feb 2025 11:29:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://dash-resources.com/wp-content/uploads/2024/12/cropped-dash-logo-favicon-512-32x32.png</url>
	<title>Archives des graph | dash-resources.com</title>
	<link>https://dash-resources.com/tag/graph/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to animate Dash Graphs</title>
		<link>https://dash-resources.com/how-to-animate-dash-graphs/</link>
		
		<dc:creator><![CDATA[Fran]]></dc:creator>
		<pubDate>Sun, 02 Feb 2025 21:47:38 +0000</pubDate>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[graph]]></category>
		<guid isPermaLink="false">https://dash-resources.com/?page_id=659</guid>

					<description><![CDATA[<p>The animate and animation_options parameters in Dash&#8217;s Graph component control how your visualizations transition between updates. These parameters are essential for creating smooth, interactive data [...]</p>
<p>L’article <a href="https://dash-resources.com/how-to-animate-dash-graphs/">How to animate Dash Graphs</a> est apparu en premier sur <a href="https://dash-resources.com">dash-resources.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="breadcrumbs align  wp-block-bcn-breadcrumb-trail has-text-color has-background" vocab="https://schema.org/" typeof="BreadcrumbList">
	<span></span>
	<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the graph Tag archives." href="https://dash-resources.com/tag/graph/" class="archive taxonomy post_tag current-item" aria-current="page"><span property="name">graph</span></a><meta property="position" content="1"></span></div>



<h1 id=''  id="boomdevs_1" class="wp-block-heading is-style-default" ></h1>


        
            
            <div class="fit_content">
                <div class="bd_toc_container" data-fixedWidth="">
                    <div class="bd_toc_wrapper" data-wrapperPadding="48px">
                        <div class="bd_toc_wrapper_item">
                            <div class="bd_toc_header active" data-headerPadding="2px">
                                <div class="bd_toc_header_title">
                                    Table of Contents                                </div>
                                <div class="bd_toc_switcher_hide_show_icon">
                                    <span class="bd_toc_arrow"></span>                                </div>
                            </div>
                            <div class="bd_toc_content list-type-disc">
                                <div class="bd_toc_content_list ">
                                    <div class='bd_toc_content_list_item'>    <ul>
      <li class="first">
        <a href="#how-do-animations-work">How do animations work?</a>
      </li>
      <li>
        <a href="#official-documentation">Official Documentation</a>
        <ul class="menu_level_2">
          <li class="first last">
            <a href="#parameter-values">Parameter Values:</a>
          </li>
        </ul>
      </li>
      <li>
        <a href="#code-examples-and-use-cases">Code Examples and Use Cases</a>
        <ul class="menu_level_2">
          <li class="first">
            <a href="#1-basic-animation-animate=true">1. Basic Animation (animate=True)</a>
          </li>
          <li class="last">
            <a href="#2-customized-animation-with-options">2. Customized Animation with Options</a>
          </li>
        </ul>
      </li>
      <li class="last">
        <a href="#best-practices-tips">Best Practices &amp; Tips</a>
      </li>
    </ul>
</div>                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layout_toggle_button">
                        <span class="bd_toc_arrow"></span>
                    </div>
                </div>
            </div>




<p>The <code>animate</code> and <code>animation_options</code> parameters in Dash&#8217;s Graph component control how your visualizations transition between updates. These parameters are essential for creating smooth, interactive data visualizations that respond to user input or real-time data updates.</p>



<h2 id='how-do-animations-work'  id="boomdevs_2" class="wp-block-heading" >How do animations work?</h2>



<p>When enabled, animations create smooth transitions between graph updates instead of abrupt changes. This includes transitions for data points, axes ranges, and other visual elements. The animations can be customized using <code>animation_options</code> to control timing, easing, and transition modes.</p>



<h2 id='official-documentation'  id="boomdevs_3" class="wp-block-heading" >Official Documentation</h2>



<p>From the <a href="https://dash.plotly.com/dash-core-components/graph#graph-properties">documentation</a>:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><strong><code>animate</code></strong> (<em>boolean</em>; default <code>False</code>): Beta: If True, animate between updates using plotly.js&#8217;s <code>animate</code> function.</p>



<p><strong><code>animation_options</code></strong> (<em>dict</em>; default <code>{ frame: { redraw: False, }, transition: { duration: 750, ease: 'cubic-in-out', },}</code>): Beta: Object containing animation settings. Only applies if <code>animate</code> is <code>True</code>.</p>
</blockquote>



<h3 id='parameter-values'  id="boomdevs_4" class="wp-block-heading" >Parameter Values:</h3>



<h4 id='animate'  id="boomdevs_5" class="wp-block-heading" >animate</h4>



<ol class="wp-block-list">
<li><code>True</code>: Enables automatic animations for all updates</li>



<li><code>False</code> (default): Disables animations</li>
</ol>



<h4 id='animate-options'  id="boomdevs_6" class="wp-block-heading" >animate_options</h4>



<p>The <code>animate_options</code> dictionary can include:</p>



<pre class="wp-block-code"><code lang="python" class="language-python">{
    'frame': {
        'redraw': True    # Whether to redraw the entire graph
    },
    'transition': {
        'duration': 500,  # Duration of transition between frames
        'easing': 'cubic-in-out'  # Easing function to use
    },
    'mode': 'immediate'  # Animation mode
}</code></pre>



<p>The documentation do not say exactly what <code>redraw</code> does. As its impact is unclear, we recommend keeping it to <code>True</code>. </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Defining <code>redraw</code>: Setting <code>redraw: false</code> is an optimization for scatter plots so that animate just makes changes without redrawing the whole plot. For other plot types, such as contour plots, every frame <strong>must</strong> be a total plot redraw, i.e. <code>redraw: true</code>.</p>
</blockquote>



<p class="callout"><strong>Good to know</strong>: under the hood, the plotly charting library is handling animations. You will therefore find more information on this page: <a href="https://plotly.com/python/animations/">https://plotly.com/python/animations/</a>.</p>



<p></p>



<h2 id='code-examples-and-use-cases'  id="boomdevs_7" class="wp-block-heading" >Code Examples and Use Cases</h2>



<h3 id='1-basic-animation-animate=true'  id="boomdevs_8" class="wp-block-heading" >1. Basic Animation (animate=True)</h3>



<p>Use this for simple animations with default settings:</p>



<pre class="wp-block-code"><code lang="python" class="language-python">html.Div([
    dcc.Graph(
        animate=True,
        figure=base_figure,
        style={'height': '100%'}
    )
], style={
    'width': '100%',
    'height': '400px',
    'border': '1px solid #ddd',
    'padding': '10px'
})</code></pre>



<iframe src="https://scripts.dash-resources.com/graph/animate1.py/" width="100%" height="500" frameBorder="0"></iframe>



<h3 id='2-customized-animation-with-options'  id="boomdevs_9" class="wp-block-heading" >2. Customized Animation with Options</h3>



<p>Use this when you need precise control over animation timing and behavior:</p>



<pre class="wp-block-code"><code lang="python" class="language-python"># Example of linear, 2s animation
html.Div([
    dcc.Graph(
        figure=fig
        animate=True,
        animation_options={
            'transition': {
                'duration': 500,
                'easing': 'linear'
            }
        },
    )
])</code></pre>



<iframe src="https://scripts.dash-resources.com/graph/animate2.py/" width="100%" height="600" frameBorder="0"></iframe>



<p>The easing parameter will accept all following values (<a href="https://plotly.com/python/reference/layout/#layout-transition-easing">source</a>):</p>



<p><code>"linear"</code> | <code>"quad"</code> | <code>"cubic"</code> | <code>"sin"</code> | <code>"exp"</code> | <code>"circle"</code> | <code>"elastic"</code> | <code>"back"</code> | <code>"bounce"</code> | <code>"linear-in"</code> | <code>"quad-in"</code> | <code>"cubic-in"</code> | <code>"sin-in"</code> | <code>"exp-in"</code> | <code>"circle-in"</code> | <code>"elastic-in"</code> | <code>"back-in"</code> | <code>"bounce-in"</code> | <code>"linear-out"</code> | <code>"quad-out"</code> | <code>"cubic-out"</code> | <code>"sin-out"</code> | <code>"exp-out"</code> | <code>"circle-out"</code> | <code>"elastic-out"</code> | <code>"back-out"</code> | <code>"bounce-out"</code> | <code>"linear-in-out"</code> | <code>"quad-in-out"</code> | <code>"cubic-in-out"</code> | <code>"sin-in-out"</code> | <code>"exp-in-out"</code> | <code>"circle-in-out"</code> | <code>"elastic-in-out"</code> | <code>"back-in-out"</code> | <code>"bounce-in-out"</code></p>



<h2 id='best-practices-tips'  id="boomdevs_10" class="wp-block-heading" >Best Practices &amp; Tips</h2>



<ul class="wp-block-list">
<li>Keep transitions under 1000ms for optimal user experience (150-300ms are good!).</li>



<li>Remember to update the figure layout (x_min, x_max, &#8230;) if you add new points or modify data, otherwise it might not become visible.</li>
</ul>



<p></p>
<p>L’article <a href="https://dash-resources.com/how-to-animate-dash-graphs/">How to animate Dash Graphs</a> est apparu en premier sur <a href="https://dash-resources.com">dash-resources.com</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to make responsive Dash Graphs</title>
		<link>https://dash-resources.com/how-to-make-responsive-dash-graphs/</link>
		
		<dc:creator><![CDATA[Fran]]></dc:creator>
		<pubDate>Sun, 02 Feb 2025 19:49:35 +0000</pubDate>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[graph]]></category>
		<guid isPermaLink="false">https://dash-resources.com/?page_id=631</guid>

					<description><![CDATA[<p>How works the responsive parameter? The responsive parameter in Dash&#8217;s Graph component controls how your graph responds to window resizing and container element changes. This [...]</p>
<p>L’article <a href="https://dash-resources.com/how-to-make-responsive-dash-graphs/">How to make responsive Dash Graphs</a> est apparu en premier sur <a href="https://dash-resources.com">dash-resources.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="breadcrumbs align  wp-block-bcn-breadcrumb-trail has-text-color has-background" vocab="https://schema.org/" typeof="BreadcrumbList">
	<span></span>
	<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the graph Tag archives." href="https://dash-resources.com/tag/graph/" class="archive taxonomy post_tag current-item" aria-current="page"><span property="name">graph</span></a><meta property="position" content="1"></span></div>


        
            
            <div class="fit_content">
                <div class="bd_toc_container" data-fixedWidth="">
                    <div class="bd_toc_wrapper" data-wrapperPadding="48px">
                        <div class="bd_toc_wrapper_item">
                            <div class="bd_toc_header active" data-headerPadding="2px">
                                <div class="bd_toc_header_title">
                                    Table of Contents                                </div>
                                <div class="bd_toc_switcher_hide_show_icon">
                                    <span class="bd_toc_arrow"></span>                                </div>
                            </div>
                            <div class="bd_toc_content list-type-disc">
                                <div class="bd_toc_content_list ">
                                    <div class='bd_toc_content_list_item'>    <ul>
      <li class="first">
        <a href="#how-works-the-responsive-parameter">How works the responsive parameter?</a>
      </li>
      <li>
        <a href="#official-documentation">Official documentation</a>
        <ul class="menu_level_2">
          <li class="first last">
            <a href="#parameter-values">Parameter Values:</a>
          </li>
        </ul>
      </li>
      <li>
        <a href="#code-examples-and-use-cases">Code Examples and Use Cases</a>
        <ul class="menu_level_2">
          <li class="first">
            <a href="#1-fully-responsive-graph-responsive=true">1. Fully Responsive Graph (responsive=True)</a>
          </li>
          <li>
            <a href="#2-non-responsive-graph-responsive=false">2. Non-Responsive Graph (responsive=False)</a>
          </li>
          <li>
            <a href="#3-auto-responsive-graph-responsive=-auto">3. Auto-Responsive Graph (responsive=&#039;auto&#039;)</a>
          </li>
          <li class="last">
            <a href="#4-responsive-with-constraints">4. Responsive with Constraints</a>
          </li>
        </ul>
      </li>
      <li class="last">
        <a href="#best-practices-tips">Best practices &amp; tips</a>
      </li>
    </ul>
</div>                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layout_toggle_button">
                        <span class="bd_toc_arrow"></span>
                    </div>
                </div>
            </div>




<h2 id='how-works-the-responsive-parameter'  id="boomdevs_1" class="wp-block-heading" >How works the responsive parameter?</h2>



<p>The <code>responsive</code> parameter in Dash&#8217;s Graph component controls how your graph responds to window resizing and container element changes. This is crucial for creating graphs that work well across different screen sizes and layouts.</p>



<h2 id='official-documentation'  id="boomdevs_2" class="wp-block-heading" >Official documentation</h2>



<p>From the <a href="https://dash.plotly.com/dash-core-components/graph">documentation</a>:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><strong><code>responsive</code></strong> (<em>a value equal to: true, false or &#8216;auto&#8217;</em>; default <code>'auto'</code>): If True, the Plotly.js plot will be fully responsive to window resize and parent element resize event. This is achieved by overriding <code>config.responsive</code> to True, <code>figure.layout.autosize</code> to True and unsetting <code>figure.layout.height</code> and <code>figure.layout.width</code>. If False, the Plotly.js plot not be responsive to window resize and parent element resize event. This is achieved by overriding <code>config.responsive</code> to False and <code>figure.layout.autosize</code> to False. If &#8216;auto&#8217; (default), the Graph will determine if the Plotly.js plot can be made fully responsive (True) or not (False) based on the values in <code>config.responsive</code>, <code>figure.layout.autosize</code>, <code>figure.layout.height</code>, <code>figure.layout.width</code>. This is the legacy behavior of the Graph component. Needs to be combined with appropriate dimension / styling through the <code>style</code> prop to fully take effect.</p>
</blockquote>



<h3 id='parameter-values'  id="boomdevs_3" class="wp-block-heading" >Parameter Values:</h3>



<ol class="wp-block-list">
<li><code>True</code>: Forces the graph to be fully responsive</li>



<li><code>False</code>: Disables responsiveness</li>



<li><code>'auto'</code> (default): Determines responsiveness based on other settings</li>
</ol>



<h2 id='code-examples-and-use-cases'  id="boomdevs_4" class="wp-block-heading" >Code Examples and Use Cases</h2>



<h3 id='1-fully-responsive-graph-responsive=true'  id="boomdevs_5" class="wp-block-heading" >1. Fully Responsive Graph (responsive=True)</h3>



<p>Use this when you want your graph to always adapt to its container size, horizontally and vertically:</p>



<pre class="wp-block-code"><code lang="python" class="language-python"># Container with fluid width
html.Div([ 
      dcc.Graph(
          responsive=True,
          figure=base_figure, 
          style={'height': '100%'}  # Necessary to adapt vertically
      )
  ], style={
      'width': '100%',  # Fluid width
      'height': '400px',
      'border': '2px solid #2196F3',
      'padding': '10px',
      'margin': '10px 0'
  })
</code></pre>



<iframe src="https://scripts.dash-resources.com/graph/responsive1.py/" width="100%" height="700" frameBorder="0"></iframe>



<p>In most cases, the container should have a fixed height to make this work. You can however make the container height 100% of its own height using CSS flexbox.</p>



<h3 id='2-non-responsive-graph-responsive=false'  id="boomdevs_6" class="wp-block-heading" >2. Non-Responsive Graph (responsive=False)</h3>



<p>Use this when you need fixed dimensions regardless of screen size:</p>



<pre class="wp-block-code"><code lang="python" class="language-python"># Container with fixed width
html.Div([
    dcc.Graph(
        responsive=False,
        figure={
            'data': fig['data'],
            'layout': {
                'width': 500,  # Fixed width
                'height': 300  # Fixed height
            }
        }
    )
], style={
    'width': '800px',
    'height': '400px',
    'border': '2px solid #4CAF50',
    'padding': '10px'
})
</code></pre>



<iframe loading="lazy" src="https://scripts.dash-resources.com/graph/responsive2.py/" width="100%" height="700" frameBorder="0"></iframe>



<p>Note that in this case, the graph will take the default dimensions in the figure layout. The container should have greater width and heights than the figure, or the graph will overflow.</p>



<p>Setting CSS style with <code>width</code> and <code>height</code> properties on the graph will have the negative effect of making the container believe that your graph is smaller or larger than what it is really.</p>



<h3 id='3-auto-responsive-graph-responsive=-auto'  id="boomdevs_7" class="wp-block-heading" >3. Auto-Responsive Graph (responsive=&#8217;auto&#8217;)</h3>



<p>Use this default setting when you want the graph to determine responsiveness based on its layout settings:</p>



<pre class="wp-block-code"><code lang="python" class="language-python"># Container with max-width constraint
html.Div([
    dcc.Graph(
        responsive='auto',
        figure={
            'data': fig['data'],
            'layout': {
                'title': 'Auto-Responsive Graph',
                'autosize': True,
                'height': 350  # Fixed height only
            }
        }
    )
], style={
    'width': '100%',
    'height': '400px',
    'border': '2px solid #FF9800',
    'padding': '10px'
})
</code></pre>



<iframe loading="lazy" src="https://scripts.dash-resources.com/graph/responsive3.py/" width="100%" height="700" frameBorder="0"></iframe>



<p>In this example, the graph is horizontally responsive but not vertically responsive as its height is fixed in the figure layout.</p>



<p>The &#8216;auto&#8217; setting essentially lets you have fine-grained control over what aspects of your graph should be responsive while preserving other dimensional constraints you&#8217;ve set. Using <code>responsive=True</code> or <code>False</code> is often clearer.</p>



<h3 id='4-responsive-with-constraints'  id="boomdevs_8" class="wp-block-heading" >4. Responsive with Constraints</h3>



<p>Use this when you want responsiveness within certain bounds:</p>



<pre class="wp-block-code"><code lang="python" class="language-python"># Container with min/max constraints
html.Div([
    dcc.Graph(
        responsive=True,
        figure=fig
    )
], style={
    'width': '100%',
    'minWidth': '200px',
    'maxWidth': '500px',
    'height': '400px',
    'border': '2px solid #E91E63',
    'padding': '10px'
})
</code></pre>



<iframe loading="lazy" src="https://scripts.dash-resources.com/graph/responsive4.py/" width="100%" height="700" frameBorder="0"></iframe>



<p>This case differs from the first one in the sense that 1) the graph height is not fluid and 2) there are maximum and minimum width specified on the container.</p>



<h2 id='best-practices-tips'  id="boomdevs_9" class="wp-block-heading" >Best practices &amp; tips</h2>



<ul class="wp-block-list">
<li>If you want the graph to have the same height as the container: always explicit the container’s height, otherwise setting <code>height: 100%</code> on the graph will not work.</li>



<li>To simplify things, keep the graph has the only child of your container.</li>



<li>Add padding to prevent graph from touching container edges, use the CSS <code>overflow</code> if you need to hide the overflowing content or make scrollable container.</li>



<li>Use percentage widths for fluid layouts, combined with CSS properties like <code>max-width</code> and <code>max-height</code>.</li>
</ul>



<p></p>
<p>L’article <a href="https://dash-resources.com/how-to-make-responsive-dash-graphs/">How to make responsive Dash Graphs</a> est apparu en premier sur <a href="https://dash-resources.com">dash-resources.com</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
