<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Michael Waskom on Medium]]></title>
        <description><![CDATA[Stories by Michael Waskom on Medium]]></description>
        <link>https://medium.com/@michaelwaskom?source=rss-d706dd12d3e4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EFvsWh1_5jElDVJ6sizjEw.jpeg</url>
            <title>Stories by Michael Waskom on Medium</title>
            <link>https://medium.com/@michaelwaskom?source=rss-d706dd12d3e4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 07:34:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@michaelwaskom/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Announcing the release of seaborn 0.12]]></title>
            <link>https://michaelwaskom.medium.com/announcing-the-release-of-seaborn-0-12-f26266ddbd8f?source=rss-d706dd12d3e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f26266ddbd8f</guid>
            <category><![CDATA[seaborn]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Michael Waskom]]></dc:creator>
            <pubDate>Tue, 06 Sep 2022 12:50:42 GMT</pubDate>
            <atom:updated>2022-09-06T12:50:42.400Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RYrbI_N1aF7-3U3QgmxGVw.png" /></figure><p>Today sees the 0.12 release of <a href="http://seaborn.pydata.org/">seaborn</a>, a Python library for data visualization. This is a major release that introduces an entirely new API along with numerous enhancements to existing functionality. This post highlights some notable features; see the <a href="http://seaborn.pydata.org/whatsnew/v0.12.0.html">release notes</a> for complete details.</p><h3>Introducing the objects interface</h3><p>The biggest news in this release is the debut of the seaborn.objects interface, an entirely new approach to specifying graphics in seaborn.</p><p>The objects interface is the product of several years of work designing and implementing an API that is more declarative, composable, and extensible.</p><p>Taking inspiration from Wilkinson’s <a href="https://www.amazon.com/Grammar-Graphics-Statistics-Computing/dp/0387245448">grammar of graphics </a>— and its implementation in libraries such as ggplot2 and vega-lite — the objects interface offers a collection of classes that can be flexibly combined to specify a wide range of statistical graphics.</p><p>Here is a simple example, showing how you would make a scatter plot with dots colored by a categorical variable:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PhM6J0CWGezoYVuJ4acW7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NEsMKtYG51rUxmruLFLgeg.png" /></figure><p>Like seaborn’s existing functions, you can get a complete plot by specifying only a minimal amount of information: where the data is coming from and how it should be visualized.</p><p>But while the plotting functions achieve simplicity by constraining what you can do with them, the objects interface will let you accomplish a lot more.</p><figure><img alt="A code example demonstrating how to make a more complex plot, with multiple facets and data transformations." src="https://cdn-images-1.medium.com/max/1024/1*6NPP_no6XK7SzRp2IpBfDg.png" /></figure><figure><img alt="An example of a more complex plot that can be made with the seaborn objects interface, which has multiple facets and shows ranges derived by statistically transforming the data." src="https://cdn-images-1.medium.com/max/1024/1*FNnR9NrHwKADb9LCTsT0qw.png" /></figure><p>The design aims to alleviate some pain points that have emerged over the past decade of seaborn’s development and use. Namely, it will support a more cohesive customization experience, allowing most operations to be expressed within a common interface and avoiding the need for users to consult the matplotlib documentation when polishing a plot.</p><figure><img alt="A third example demonstrating the code to generate a more complete and polished plot, which can all be expressed within a common interface." src="https://cdn-images-1.medium.com/max/1024/1*i90zbkkuO0AltjWhVDdSaw.png" /></figure><figure><img alt="A seaborn plot showing the growth in health spending and life expectancy for 6 countries over the past 30 years, where the USA appears as an outlier with high spending but poor health." src="https://cdn-images-1.medium.com/max/1024/1*_aQJ6dT0uedrl5mBGyKBMA.png" /></figure><p>As this is the first official release, there will no doubt be some rough edges, and some key features have yet to be implemented. But it is ready for broad use. To learn more, check out the new <a href="https://seaborn.pydata.org/tutorial/objects_interface.html">tutorial</a>, which introduces key concepts and demonstrates various usage patterns.</p><h3>Enhancements to existing functionality</h3><p>Not interested in the new interface? That’s OK: the existing functions aren’t going anywhere. While the focus is on the completely new tools, there are also <a href="http://seaborn.pydata.org/whatsnew/v0.12.0.html">a number of enhancements and fixes</a> to the old ones.</p><p>These enhancements include some long-desired features, like a much more flexible approach to specifying error bars (complete with <a href="https://seaborn.pydata.org/tutorial/error_bars.html">a new tutorial</a>). The categorical scatterplot functions (stripplot and swarmplot) have been refactored: their default behavior is now more consistent with the rest of the library, and they’re sporting some <a href="https://seaborn.pydata.org/whatsnew/v0.12.0.html#modernization-of-categorical-scatterplots">new features</a> that make them more flexible and easier to use. And all plotting functions now allow you to pass the data source first, making it easier to pipe a pandas dataframe into a seaborn plot.</p><p>Finally, <a href="https://seaborn.pydata.org/">the documentation</a> has been revamped using the wonderful <a href="https://pydata-sphinx-theme.readthedocs.io/en/stable/">PyData sphinx theme</a>. Not only does it look better, it should be more accessible and easier to navigate. And there is a new <a href="https://seaborn.pydata.org/faq.html">FAQ page</a> with answers to common questions and explanations of notable gotchas.</p><h3>How to upgrade</h3><p>When you’re ready to upgrade, the new version is just a pip install away:</p><pre>pip install seaborn==0.12.0</pre><p>I hope you find it useful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f26266ddbd8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three common seaborn difficulties]]></title>
            <link>https://michaelwaskom.medium.com/three-common-seaborn-difficulties-10fdd0cc2a8b?source=rss-d706dd12d3e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/10fdd0cc2a8b</guid>
            <category><![CDATA[seaborn]]></category>
            <category><![CDATA[matplotlib]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Michael Waskom]]></dc:creator>
            <pubDate>Mon, 22 Feb 2021 13:06:29 GMT</pubDate>
            <atom:updated>2021-02-22T16:28:57.765Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="Some examples plots that seaborn can create, if everything goes well" src="https://cdn-images-1.medium.com/max/1024/1*Cgqkt7lTWELcNV4v3KYsRw.png" /></figure><h4>Explaining some aspects of using seaborn that most often confound newcomers</h4><p>This post aims to explain three of the most common difficulties encountered by users of <a href="http://seaborn.pydata.org/">seaborn</a>, a Python library for data visualization. My hope is that this post can be a helpful resource for users who have read through some of the documentation — which uses toy datasets and focuses on simple tasks — but are now struggling to apply the lessons to their own work.</p><h3>You (might) need to reformat your data</h3><p>Seaborn’s plotting functions are most expressive when provided with a “<a href="https://vita.had.co.nz/papers/tidy-data.html">tidy</a>” long-form dataset. With data formatted this way, you can pass the full dataset and select the columns that you want to visualize by assigning the column names to different roles (x, y, hue, etc.).</p><p>But we often work with datasets that are not naturally stored in a tidy format. For example, you might keep a spreadsheet with your household budget that looks like this:</p><figure><img alt="A “messy” data table" src="https://cdn-images-1.medium.com/max/1024/1*b94bBifsFTd37loR91bK8A.png" /><figcaption>A “messy” table representing a household budget.</figcaption></figure><p>This is a perfectly fine representation of the data from a human perspective: it’s easy to read off the change in your food expenses from year to year. But it would be difficult to <em>plot </em>those changes, because the “year” variable isn’t explicitly represented. Rather, it’s represented by (a subset of) the column names.</p><figure><img alt="A “tidy” data table, in long-form" src="https://cdn-images-1.medium.com/max/468/1*Shp2ASOUDYw9eKUd5m2JWA.png" /><figcaption>The same budget, but represented in a “tidy” long-form table.</figcaption></figure><p>The table on the left shows the same data after “melting” into long-form format. Now the three variables are represented in separate columns and can be explicitly assigned to roles in a plot. The command for this transformation is:</p><pre>budget_long = budget.melt(<br>    id_vars=&quot;Category&quot;,<br>    var_name=&quot;Year&quot;, <br>    value_name=&quot;Expense&quot;,<br>)</pre><p>It can be difficult to give a general recipe for converting data to long-form, because the details will depend on the original format, and this will be different for every dataset. It can be helpful to think backwards from the plot: what will you assign to x, y, or other roles? How is that information currently encoded in your DataFrame? Once you get the hang of it, preparing your data will become straightforward. And long-form data is useful beyond seaborn: you’ll also need this format to perform group-by aggregations in pandas or to specify a design matrix in statsmodels.</p><p>But, if learning how to reformat your data still feels like an obstacle, I have good news: it might not be necessary!</p><p>I said before that seaborn is <em>most</em> expressive when provided with long-form data. But (nearly) all seaborn functions can understand “wide-form” data too. Wide-form data can be a DataFrame, a 2D numpy array, or even a collection of vectors (perhaps of different lengths) held in a Python dictionary or list. To understand all of the possibilities, read <a href="http://seaborn.pydata.org/tutorial/data_structure.html">this chapter</a> of the seaborn user guide. The key thing is that the values inside the table (i.e. not the index or column names) must represent a single variable.</p><p>The original budget table above won’t quite work, because it still represents one variable with one column in the table and a different variable across the other columns. But if you do budget.set_index(&quot;Category&quot;), you’ll have a tidy “wide-form” table that you can visualize by passing to data.</p><figure><img alt="The rules that lineplot and boxplot use for wide-form data" src="https://cdn-images-1.medium.com/max/1024/0*PKQuNJ6bTCBs6ljA" /><figcaption>There are many options for passing wide-form data, but different functions will interpret it differently.</figcaption></figure><p>The drawback is that each function has a fixed way of plotting wide-form data, and if you want to do something different, you’ll need to change the <em>data</em>, not the way you call the function. But it’s still useful for a quick peak.</p><p>And if you’d rather not think about pandas DataFrame structure, you can also pass vectors of data directly to x and y. You can even mix names that reference columns in data and vectors that directly represent other variables. For more complex plots, this approach may require writing a for-loop and calling the plotting function multiple times (rather than, say, using a long-form hue variable). Users of other statistical programming languages are sometimes made to feel bad for writing a for loop, but I don’t think that’s true with Python. If this approach is easiest for you, you should use it!</p><h3>There are two kinds of plotting functions</h3><p>The second difficulty is typically encountered when you try to combine a seaborn plot with a matplotlib figure that has multiple axes.</p><p>As you may know, matplotlib has two interfaces, The <em>implicit</em> interface — comprising pyplot functions like plt.plot andplt.bar— draws onto the “current axes” as tracked by an internal state machine. The <em>explicit</em> interface —comprising Axes methods like ax.plot, ax.bar — draws onto the specific Axes that the method is attached to.</p><pre>plt.plot(x, y)  <em># Plots on the &quot;current&quot; axes, creating it if needed</em><br>f, axs = plt.subplots(ncols=2)  <em># Creates a new figure with two axes</em><br>axs[0].plot(x, y)  <em># Plots on the first axes of the new figure</em><br>plt.plot(x, y)  <em># Plots on the second axes of the new figure</em></pre><p>Both approaches have their use: the implicit interface is quick and easy, while the explicit interface is (slightly) more verbose but better for making complex figures. Seaborn tries to support both styles too. Most plotting functions plot onto the “current” matplotlib axes by default and can be directed towards a specific existing Axes by setting the ax= parameter.</p><pre>sns.lineplot(x=x, y=y)  # Plots on the &quot;current&quot; axes<br>f, axs = plt.subplots(ncols=2)  # Creates a new figure<br>sns.lineplot(x=x, y=y, ax=axs[0])  # Plots on the first new axes<br>sns.lineplot(x=x, y=y)  <em># Plots on the second new axes</em></pre><p>Except that’s only true for <strong>most</strong> functions. Functions in a special subset , the “figure-level” functions, create a new figure every time they are invoked.</p><p>These functions, such as relplot, displot, and catplot, work this way because they internally use a seaborn <a href="https://seaborn.pydata.org/generated/seaborn.FacetGrid.html">FacetGrid</a>, an object that can create a figure where <a href="https://seaborn.pydata.org/tutorial/axis_grids.html">subsets of the data are shown on different axes</a>. As a result, if you do something like</p><pre>f, ax = plt.subplots()<br>sns.displot(data, x=&quot;a&quot;, ax=ax)<br>sns.displot(data, x=&quot;b&quot;, ax=ax)</pre><p>You’ll end up with three figures: one with an empty Axes, and two with separate histograms. Which is not what you wanted!</p><p>This behavior is explained in the <a href="http://seaborn.pydata.org/tutorial/function_overview.html#figure-level-vs-axes-level-functions">user guide</a>, but if you haven’t come across that chapter, it can be very confusing. It doesn’t help that the names don’t clearly distinguish the two kinds of functions — in retrospect, calling the figure-level functions something like relfig , catfig would have made more sense — although you can tell when kind they are by whether ax= appears in the list of parameters and by what kind of object they return.</p><p>There are a few other complexities, which the user guide chapter covers in detail. Notably, the figure size is parameterized differently in the figure-level functions, and they return a FacetGrid object, which has a few helpful methods that matplotlib Axes functions lack.</p><p>I <a href="http://seaborn.pydata.org/tutorial/function_overview.html#relative-merits-of-figure-level-functions">generally recommend</a> using the figure-level functions for most applications, but to make arbitrarily complex figures, you’ll need to switch to an axes-level function. There’s a one-to-one correspondence between each axes-level function and the different kinds of plots that the figure-level functions can make. So by default displot has kind=&quot;hist&quot;, corresponding to histplot, but displot(..., kind=&quot;kde&quot;) corresponds to kdeplot.</p><h3>Categorical plots will always be categorical</h3><p>Several seaborn functions specialize in creating plots where one of the axes corresponds to a <a href="http://seaborn.pydata.org/tutorial/categorical.html"><em>categorical</em></a> variable: a variable whose values do not (necessarily) bear a quantitative relationship to each other. Examples would include country of origin (which is both categorical and unordered) and age group (which is ordered, but still categorical). Such variables are often encoded with strings, and at the time these functions were created, matplotlib was not able to interpret string data. So the seaborn functions internally map from the data values to ordinal indices (0, 1, …, <em>n</em>), which are then passed to matplotlib.</p><p>The surprise is that seaborn’s categorical functions<em> </em><strong>always</strong> do this.</p><p>As a consequence, numeric variables will be treated as categorical. The (sorted) unique values will be mapped ordinal indices, and a label will be drawn for every value. Sometimes, this makes sense and is helpful. For example, in the “tips” dataset, the size variable is numeric, but it only takes a few evenly-spaced values, and the default tick labels that you get from the categorical pointplot are more informative than those from lineplot:</p><figure><img alt="Sensible output from pointplot with a numeric x variable" src="https://cdn-images-1.medium.com/max/900/1*A9Ya0Qs9_5S53Dh7X5lJWA.png" /><figcaption>Sometimes it makes sense to make treat a numeric variable as categorical…</figcaption></figure><p>But if you draw a line with more densely-sampled values, they will all be labeled, and the x axis will be impossible to read:</p><figure><img alt="Nonsensical output from pointplot with a numeric x variable" src="https://cdn-images-1.medium.com/max/900/1*r1LI86b-JTv04Mo1Jdo8KA.png" /><figcaption>…but other times, it makes a huge mess.</figcaption></figure><p>It won’t help to do ax.set_xticks([20, 40]), as that will label the 20th and 40th data points, not the data points with those numeric values (because, remember, all matplotlib sees here are the index values, not the original numbers). And even if you did set the labels properly, the plot probably wouldn’t be what you want, because each datapoint would be drawn at a fixed distance from its neighbors rather than at a distance proportional to their values.</p><p>This issue also surprises users who want to layer categorical and non-categorical functions onto the same plot. Consider the following example, which calls stripplot and lineplot with the same arguments:</p><figure><img alt="Nonsensical output when layering a lineplot onto a stripplot" src="https://cdn-images-1.medium.com/max/900/1*hFty4x-7N7xv7C8jYiju3w.png" /><figcaption>The stripplot treats size as categorical, but the lineplot doesn’t, so the line is shifted to the right.</figcaption></figure><p>Now that you know the strips are actually drawn at 0, 1, …, <em>n — </em>with the tick labels set to strings representing the corresponding values — you should understand why this figure looks the way it does. But it’s a common source of surprise and confusion.</p><p>For now, my general advice would be to avoid mixing categorical and non-categorical plots on the same Axes. You can substitute pointplot for lineplot and stripplot for scatterplot where needed.</p><p>These days, most matplotlib functions can handle string data, using the same basic approach as seaborn: strings are mapped to 0, 1, …, <em>n</em> indices. As a result, the “non-categorical” seaborn functions can handle categorical variables just fine, and the lines between the two kinds of functions have become blurred. So it’s also possible to force categorical treatment in non-categorical plots by converting your data to strings.</p><p>The <a href="https://github.com/mwaskom/seaborn/issues/2429">next release</a> of seaborn will include some major enhancements to the categorical functions, which will further smooth away some of these difficulties. Notably, it will become possible to maintain the original scale of numeric (or datetime) data on the “categorical” axis. But you’ll have to explicitly ask for that, so it will be good to keep a slightly modified version of this lesson in mind: categorical plots will always (by default) be categorical.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10fdd0cc2a8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Announcing the release of seaborn 0.11]]></title>
            <link>https://michaelwaskom.medium.com/announcing-the-release-of-seaborn-0-11-3df0341af042?source=rss-d706dd12d3e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3df0341af042</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[seaborn]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Michael Waskom]]></dc:creator>
            <pubDate>Tue, 08 Sep 2020 15:12:57 GMT</pubDate>
            <atom:updated>2020-09-08T15:12:57.679Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gM_WIfx7MXOO7jzsPm-Y0Q.png" /></figure><p>Today sees the 0.11 release of <a href="https://seaborn.pydata.org/">seaborn</a>, a Python library for data visualization. This is a major update with a number of exciting new features, updated APIs, and better documentation. This article highlights some of the notable features and updates; see the seaborn website for <a href="https://seaborn.pydata.org/whatsnew.html">detailed release notes</a>.</p><h3>Modernized distribution plots</h3><p>The distribution plots have been completely rewritten for this release, modernizing the APIs, enhancing existing capabilities, and adding exciting new features. With these changes, you can visualize conditional distributions via semantic mapping and faceting with just a single declarative function call:</p><pre>sns.displot(<br>    data=penguins, kind=&quot;hist&quot;, kde=True,<br>    x=&quot;flipper_length_mm&quot;, col=&quot;island&quot;, hue=&quot;species&quot;,<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SrSrGL9Nv4HGdJlFUfcGmw.png" /><figcaption>A faceted plot of conditional histograms, augmented with kernel density smoothing.</figcaption></figure><p>(This example uses Allison Horst’s fun new <a href="https://allisonhorst.github.io/palmerpenguins/">Palmer Penguins</a> dataset).</p><p>This major new function, <a href="https://seaborn.pydata.org/generated/seaborn.displot.html">displot</a>, offers a figure-level interface to the various forms of distribution plots in seaborn: histograms, kernel density estimates, empirical distributions, and rug plots. Most of these options support both univariate and bivariate visualizations:</p><pre>g = sns.displot(<br>    data=penguins, kind=&quot;kde&quot;, rug=True,<br>    x=&quot;bill_length_mm&quot;, y=&quot;bill_depth_mm&quot;,<br>    col=&quot;island&quot;, hue=&quot;species&quot;,<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fN0W1Sep1eAXFbkRAzEdtg.png" /><figcaption>Bivariate kernel density estimates, with rug plots showing individual observations.</figcaption></figure><p>Completely new to seaborn, empirical distribution (ECDF) plots are a statistical technique that facilitates quantitative comparisons between distributions:</p><pre>g = sns.displot(<br>    data=penguins, kind=&quot;ecdf&quot;,<br>    x=&quot;body_mass_g&quot;, col=&quot;sex&quot;, hue=&quot;species&quot;,<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sULrvSdEYdTmEmTI1r6d0A.png" /><figcaption>It is easier to see differences between distributions in ECDF plots than in overlapping histograms or densities.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KEh5PFmrF-nWqoPd7bPUAg.png" /><figcaption>Histograms can be computed with discrete bins and normalized to show a probability mass function. When the axes are log-scaled, the density smoothing and histogram binning occurs in log space.</figcaption></figure><p>The new distribution plots natively support categorical and datetime data, they handle log-scaled axes transparently, and there are new parameters for intuitively controlling the histogram binning and density smoothing. Histogram counts can be normalized to show either the density, probability, or frequency of observations in each bin. Multiple distributions can be layered, stacked, or dodged. Weighted estimation is possible in all distribution plots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*rCiFMcX144U7FubMWd7FSg.png" /><figcaption>Joint and paired plots are now much more powerful.</figcaption></figure><p>Now that the axes-level distribution plots support semantic mappings, seaborn’s composite plotting functions do as well. Showing the joint and marginal distributions of two variables while conditioning on a third variable is as easy as</p><pre>sns.jointplot(<br>    data=penguins,<br>    x=&quot;bill_length_mm&quot;,<br>    y=&quot;bill_depth_mm&quot;,<br>    hue=&quot;species&quot;<br>)</pre><h3>Highlights of the other features and enhancements</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dNlHolr-BH8FJHyDt0LSNg.png" /><figcaption>The “flare” colormap maps a numeric variable to the color of points or lines with better contrast at the extremes than “rocket”. Use “crest” for a cooler theme.</figcaption></figure><p>While the distribution plots have the most exciting new features, important enhancements have been made throughout the library. For example, you should now see better results when semantically mapping numeric variables in the relational plotting functions (relplot, scatterplot, and lineplot), and two new perceptually-uniform colormaps (“flare” and “crest”) have been created for use in this kind of plot.</p><p>The code that ingests data has been refactored, and support for both wide- and long-form data has been standardized and improved. While it’s most common to use seaborn with pandas dataframes and to specify data mappings using named variables, seaborn is quite flexible about how its input data can be represented. A <a href="https://seaborn.pydata.org/tutorial/data_structure.html">new chapter of the user guide</a> demonstrates this flexibility and explains how seaborn views datasets. While data ingest is not yet fully consistent across the library, it will become so over the next release cycle.</p><p>The documentation has been improved in numerous other ways, including a <a href="https://seaborn.pydata.org/tutorial/function_overview.html">new user guide chapter</a> explaining how seaborn functions are organized, including a discussion and comparison of the critical distinction between “axes-level” and “figure-level” functions. The <a href="https://seaborn.pydata.org/tutorial/color_palettes.html">color palette tutorial</a> has been revised to give more color theory background and motivation for why you would choose different color palettes. And a rewritten <a href="https://seaborn.pydata.org/tutorial/distributions.html">distribution tutorial</a> demonstrates the new features while providing guidance on how best to use each kind of plot.</p><h3>Transition to enforced keyword arguments</h3><p>With these new features comes some important API changes. Notably, the plotting functions (both old and new ones) now require nearly all of their arguments to be passed with explicit keywords. In v0.11, using positional arguments triggers only a warning, but this will become an error in future versions, so you should update your code.</p><p>As the documentation has long used explicit keywords in nearly all examples, this will hopefully not be too disruptive. Enforcing keyword arguments will make it easier to add new features to the library while keeping the function signatures organized and the function calls interpretable. Once the change is in full effect, the signatures will be reorganized so that data<em> </em>is the first argument for all functions. This will make it easier to pipe pandas dataframes into seaborn functions. And, with the enhanced support for wide-form data, it means that calling any plotting function as plot(data) will work for a very range of data formats.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sdi59N1NaQcAQbSQqSG7VA.png" /><figcaption>Bivariate histograms with categorical variables on both axes are an easy way to plot a crosstab from a tidy DataFrame.</figcaption></figure><h3>Adapting to changes in the distribution module</h3><p>The new distribution plot features are naturally disruptive. Here is some advice to help you adapt your code. Lots of effort was devoted to smoothing the transition, but it will be wise to check your plots carefully before and after updating.</p><h4>Replacing calls to distplot</h4><p>As part of these updates, the original distplot function has been deprecated and will eventually be retired. If you use distplot for histograms, it can be replaced in two ways:</p><ul><li><a href="https://seaborn.pydata.org/generated/seaborn.displot.html">displot</a>, a new figure-level function, which should be used in most situations, because it supports faceting and puts the legend outside of the plot</li><li><a href="https://seaborn.pydata.org/generated/seaborn.histplot.html">histplot</a>, a new axes-level function, which should be used in situations where you need to plot a histogram onto an existing matplotlib figure</li></ul><p>For simple plots where x is a vector of data, displot(x) and histplot(x) are drop-in replacements for distplot(x). Both functions also allow you to add a KDE curve by setting kde=True. As an enhancement, the new functions will plot a KDE over a histogram that shows counts, rather than requiring density normalization. If you use distplot to show <em>just </em>a KDE, use either displot with kind=&quot;kde&quot; or the axes-level kdeplot.</p><p>It is likely that the similarity in names between displot and distplot will cause some confusion during the transition, which is regrettable. There was really no better name for a new figure-level function that makes distribution plots. If it helps, the etymology for “distribute” is <em>dis-</em> (apart) <em>tribure </em>(to assign), so at least the new term splits the word in the right place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ayLfOWcb-bIf20Jb3JyDGA.png" /><figcaption>Creating small multiples by faceting on a variable with many levels gives an informative summary of a dataset.</figcaption></figure><h4>Updating calls to kdeplot</h4><p>Unlike distplot, the kernel density enhancements were implemented by adapting the existing <a href="https://seaborn.pydata.org/generated/seaborn.kdeplot.html">kdeplot</a> function. Old code should continue to work, but in some cases it will trigger a FutureWarning or UserWarning if it uses a deprecated or updated API. The <a href="https://github.com/mwaskom/seaborn/pull/2104">pull request on GitHub</a> has an extensive explanation of each change.</p><p>Simple calls, like kdeplot(x) will work the same way as before. But to use the new features, you’ll need to explicitly assign your data and variables. The parameters now follow the standard data, x, y, hue API seen in other seaborn functions.</p><p>Several of the optional parameters in kdeplot have also been modified. Notably, the ambiguous bw parameter is replaced by bw_method and bw_adjust. In most cases, you will want to tweak bw_adjust: a factor that scales the default bandwidth for all distributions shown in the plot.</p><p>The old version of kdeplot could use either statsmodels or scipy to compute the density estimate. This added complexity without a clear benefit, so the statsmodels backend has been dropped in the rewrite. This means that the new version supports only Gaussian kernels. Additionally, there were some differences in how the two backends interpreted various parameters (bw, and clip are notable examples). Default behavior should be the same, but you may see differences in your plots if you were setting other values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*anqa9YITCKC_s9FO_8GaGg.png" /><figcaption>seaborn now has a proper logo — check the website for svg files</figcaption></figure><h3>Upgrading to the new version</h3><p>When you’re ready to upgrade, these features <a href="https://seaborn.pydata.org/whatsnew.html">and many more</a> are just a pip install away:</p><pre>pip install seaborn==0.11.0</pre><p>If you need help , a new <a href="https://discourse.matplotlib.org/c/3rdparty/seaborn/21">seaborn channel</a> has been created on the Matplotlib discourse forum. This complements the use of StackOverflow for targeted Q&amp;A and GitHub for reporting bugs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3df0341af042" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>