A chart walks into a bar: Altair vs. leather

In this blog post series, we’re going to compare two Data Visualization packages in the Python landscape. We will create a bar chart from dummy data, based on this example available in the Altair documentation, with each package. Furthermore, we will t…


This content originally appeared on DEV Community and was authored by João Palmeiro

In this blog post series, we're going to compare two Data Visualization packages in the Python landscape. We will create a bar chart from dummy data, based on this example available in the Altair documentation, with each package. Furthermore, we will try to follow the most straightforward implementation to compare the two APIs/charts from their defaults.

For this first installment, let's create a bar chart using Altair and then leather. The dataset looks like this:

import pandas as pd

source = pd.DataFrame(
    {
        "a": ["A", "B", "C", "D", "E", "F", "G", "H", "I"],
        "b": [28, 55, 43, 91, 81, 53, 19, 87, 52],
    }
)

From the source above, we can define a bar chart in Altair via the following snippet:

import altair as alt

alt.Chart(source).mark_bar().encode(x="a", y="b")

When we run the snippet above, we get the result below:

Bar chart created with Altair

Now, using leather, we get a similar bar chart as follows:

import leather

chart = leather.Chart()

# We cannot use a pandas DataFrame directly.
chart.add_columns(data=source.to_records(index=False).tolist())

chart.to_svg()

Bar chart created with leather

Comparing the two (default) outputs, we can highlight a number of differences:

  • The default width is larger with leather. As a result, the bars are also wider.
  • In leather, the bars are red (#e41a1c), compared to blue in Altair.
  • The bar chart created with leather does not show titles for the axes, unlike Altair.
  • There is no axis line on the Y-axis in leather. On the X-axis, the labels are not rotated (0°).
  • In Altair, there are only horizontal gridlines. In the case of leather, there are horizontal and vertical ones.
  • The default fonts are different. In leather, Monaco is used.
  • The background colors are also different. In Altair, the background color is white, while in leather, it is a (very) light gray (#f9f9f9).

On the other hand, for the Y-axis, both charts present a scale with the same domain, ending in a nice round value (100). However, the number of ticks is different.

Finally, if you have any questions or suggestions, feel free to leave a comment below!


This content originally appeared on DEV Community and was authored by João Palmeiro


Print Share Comment Cite Upload Translate Updates
APA

João Palmeiro | Sciencx (2022-03-26T20:47:40+00:00) A chart walks into a bar: Altair vs. leather. Retrieved from https://www.scien.cx/2022/03/26/a-chart-walks-into-a-bar-altair-vs-leather/

MLA
" » A chart walks into a bar: Altair vs. leather." João Palmeiro | Sciencx - Saturday March 26, 2022, https://www.scien.cx/2022/03/26/a-chart-walks-into-a-bar-altair-vs-leather/
HARVARD
João Palmeiro | Sciencx Saturday March 26, 2022 » A chart walks into a bar: Altair vs. leather., viewed ,<https://www.scien.cx/2022/03/26/a-chart-walks-into-a-bar-altair-vs-leather/>
VANCOUVER
João Palmeiro | Sciencx - » A chart walks into a bar: Altair vs. leather. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/26/a-chart-walks-into-a-bar-altair-vs-leather/
CHICAGO
" » A chart walks into a bar: Altair vs. leather." João Palmeiro | Sciencx - Accessed . https://www.scien.cx/2022/03/26/a-chart-walks-into-a-bar-altair-vs-leather/
IEEE
" » A chart walks into a bar: Altair vs. leather." João Palmeiro | Sciencx [Online]. Available: https://www.scien.cx/2022/03/26/a-chart-walks-into-a-bar-altair-vs-leather/. [Accessed: ]
rf:citation
» A chart walks into a bar: Altair vs. leather | João Palmeiro | Sciencx | https://www.scien.cx/2022/03/26/a-chart-walks-into-a-bar-altair-vs-leather/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.