{"id":175305,"date":"2023-12-17T09:43:27","date_gmt":"2023-12-17T08:43:27","guid":{"rendered":"https:\/\/liora.io\/en\/?p=175305"},"modified":"2026-02-06T08:40:49","modified_gmt":"2026-02-06T07:40:49","slug":"altair-everything-you-need-to-know-about-this-statistical-visualization-library","status":"publish","type":"post","link":"https:\/\/liora.io\/en\/altair-everything-you-need-to-know-about-this-statistical-visualization-library","title":{"rendered":"Alta\u00efr: everything you need to know about this statistical visualization library"},"content":{"rendered":"<p><strong>Altair is the brightest star in the Eagle constellation. But Altair is also a statistical visualization library that works with a visual grammar. Find out in this article how it&#8217;s used and why it&#8217;s so popular&#8230;<\/strong><\/p>\t\t\n\t\t\t<h3>What is Altair?<\/h3>\t\t\n\t\t<p><strong>Alta\u00efr<\/strong> is an <a href=\"https:\/\/liora.io\/en\/open-source-definition-use-cases-and-more\">open-source library<\/a> for declarative statistical visualization grammar, known as Vega-Alta\u00efr. It simplifies the process of creating professional-looking charts, provides a natural syntax, and produces<a href=\"https:\/\/liora.io\/en\/seaborn-everything-you-need-to-know-about-the-python-data-visualization-tool\"> high-quality visualizations that outperform Seaborn<\/a> or Matplotlib, even when dealing with datasets containing up to 100,000 points. Explore this powerful library and its full documentation to unlock its potential.<\/p>\t\t\n\t\t\t<h3>How do I install and use Alta\u00efr?<\/h3>\t\t\n\t\t<ul><li style=\"font-weight: 400;\" aria-level=\"1\">Install with pip install altair<\/li><li style=\"font-weight: 400;\" aria-level=\"1\">Import it to the notebook using altair as alt<\/li><\/ul>\t\t\n\t\t\t\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><div class=\"wp-block-button \"><a class=\"wp-block-button__link wp-element-button \" href=\"\/en\/courses\/data-ai\/\">Learn to use Alta\u00efr<\/a><\/div><\/div>\n\n\t\t\t<h3>How do you work with graphic grammar?<\/h3>\t\t\n\t\t<p>A graphical grammar is a syntax that <a href=\"https:\/\/liora.io\/en\/google-data-studio-introduction-to-googles-dataviz-tool\">creates a visualization without specification and applies it to particular data.<\/a><\/p><p>For example, we&#8217;re going to work on a dataset of baby names in the USA:<\/p><p>Here, alt is followed by the chart library, Chart, then by the declaration of the data used (DataFrame baby_names_final), the chart type, mark_chart, a simple bar chart, then by the declaration of the data, x being the names and y being the number of babies having been born with that name by selecting the year 1980.<\/p><p>The distribution of certain first names over the years :<\/p>\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/2023\/04\/image2.png\" title=\"\" alt=\"\" loading=\"lazy\">\t\t\t\t\t\t\t\t\t\t\t<figcaption>Vega Video Editor<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t<p>On the right-hand side of the graph, there&#8217;s a three-dot button that allows you to save the graph directly in various forms. View Source and View Compiled Vega allow you to read JSON files for the graph and open them with Vega Editor, which links to a github.io console as shown below:<\/p>\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/2023\/04\/image4.png\" title=\"\" alt=\"\" loading=\"lazy\">\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t<p>In Altair, <strong>data operations<\/strong> can be performed directly on the chart. You can use functions like `transform_joinaggregate` and `transform_filter` to perform operations similar to pandas&#8217; groupby and filtering. Altair offers other functions as well:<\/p><p>&#8211; `transform_calculate()`: Used to calculate new values or metrics.<br>&#8211; `transform_density()`: Estimates a density distribution.<br>&#8211; `transform_window()`: Allows you to select a subset of the data.<br>&#8211; `mark_area()`: Represents a stacked area chart.<br>&#8211; `alt.FieldOneOfPredicate`: Specifies the choice of modes to use.<\/p><p>These functions provide powerful data manipulation capabilities when <a href=\"https:\/\/liora.io\/en\/data-journalism-shaping-the-future-of-news-reporting\">creating visualizations with Altair.<\/a><\/p><p>In the following example, you can create a boxplot that displays information when you hover over the boxes. This boxplot represents the distribution of the number of children with a specific name over the years (the Tooltip). When you hover over the boxplot, a dialog box opens with specific information about the name.<\/p>\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/2023\/04\/image3.png\" title=\"\" alt=\"\" loading=\"lazy\">\t\t\t\t\t\t\t\t\t\t\t<figcaption>Box plot video<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t<p>Other features include<\/p><p>Sliders can be added<br>Display can be modified at three levels: encoding (encode), mark (mark_ followed by a type) and full display .configure_()<br>The use of geographic coordinates in GeoJSON<\/p><p>Alta\u00efr can also source its content from the Internet via URL links using alt.UrlData. Data must be in JSON and already processed. It is based on JavaScript libraries, d3j and Vega, which are often used for infographics in the Internet press.<\/p>\t\t\n\t\t\t<h3>Conclusion<\/h3>\t\t\n\t\t<p>Alta\u00efr offers a declarative,<a href=\"https:\/\/liora.io\/en\/matplotlib-master-data-visualization-in-python\"> easy-to-use alternative to matplotlib or seaborn,<\/a> with an optimized graph framework and professional tools for visualizing statistical data, with better rendering and more intuitive grammar than traditional libraries. Visualizations are an essential element in information sharing for Data Analysts or Data Scientists within the company, during internal or customer presentations.<\/p><p>If you&#8217;d like to learn more about Data Science, click on the link to Liora, our training organization for the professions of tomorrow.<\/p>\t\t\n\t\t\t\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><div class=\"wp-block-button \"><a class=\"wp-block-button__link wp-element-button \" href=\"\/en\/courses\/data-ai\/\">Discover our Data Science training courses<\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Altair is the brightest star in the Eagle constellation. But Altair is also a statistical visualization library that works with a visual grammar. Find out in this article how it&#8217;s used and why it&#8217;s so popular&#8230; What is Altair? Alta\u00efr is an open-source library for declarative statistical visualization grammar, known as Vega-Alta\u00efr. It simplifies the [&hellip;]<\/p>\n","protected":false},"author":76,"featured_media":175306,"comment_status":"open","ping_status":"open","sticky":false,"template":"elementor_theme","format":"standard","meta":{"_acf_changed":false,"editor_notices":[],"footnotes":""},"categories":[2433],"class_list":["post-175305","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-ai"],"acf":[],"_links":{"self":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/175305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/users\/76"}],"replies":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/comments?post=175305"}],"version-history":[{"count":1,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/175305\/revisions"}],"predecessor-version":[{"id":206166,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/175305\/revisions\/206166"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media\/175306"}],"wp:attachment":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media?parent=175305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/categories?post=175305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}