# Bar

A **bar chart** uses vertical bars to show comparisons between categories of data. Vertical bar charts illustrate sizes of data using different bar heights.

## The Method To Use <a href="#the-method-to-use" id="the-method-to-use"></a>

The method is `s.plt.bar()`

It must contain the following input variables:

```python
order: int
x: str
data: Union[str, DataFrame, List[Dict]]
```

And accepts the following input variables as optional:

```python
y: Optional[List[str]]
x_axis_name: Optional[str]
y_axis_name: Optional[str]
title: Optional[str]
rows_size: Optional[int]
cols_size: Optional[int]
padding: Optional[List[int]]
show_values: Optional[List[str]]
option_modifications: Optional[Dict]
```

## Examples <a href="#examples" id="examples"></a>

### 1. Default Configuration <a href="#id-1.-default-configuration" id="id-1.-default-configuration"></a>

By default the chart will have `rows_size=2` and `cols_size=12`, also it will have no padding applied. An example on how to use the default configuration is:

```python
data = [
    {'date': dt.date(2021, 1, 1), 'x': 1, 'y': 10},
    {'date': dt.date(2021, 1, 2), 'x': 2, 'y': 8},
    {'date': dt.date(2021, 1, 3), 'x': 3, 'y': 10},
    {'date': dt.date(2021, 1, 4), 'x': 4, 'y': 2},
    {'date': dt.date(2021, 1, 5), 'x': 5, 'y': 14},
]

s.plt.bar(data=data, order=0, x='date')
```

![Bar chart in the default configuration](/files/jcX5hglvJc3gXsgNcUy3)

### 2. Customization And Context <a href="#id-2.-title-axes-names-legend" id="id-2.-title-axes-names-legend"></a>

It is possible to personalize the **title** of the chart, name of each **axis**, the **legend,** changing **size** and add **padding**. One example could be obtained using:

```python
data = [
    {'date': dt.date(2021, 1, 1), 'store 1': 5, 'store 2': 10},
    {'date': dt.date(2021, 2, 1), 'store 1': 6, 'store 2': 8},
    {'date': dt.date(2021, 3, 1), 'store 1': 4, 'store 2': 10},
    {'date': dt.date(2021, 4, 1), 'store 1': 7, 'store 2': 2},
    {'date': dt.date(2021, 5, 1), 'store 1': 3, 'store 2': 14},
    {'date': dt.date(2021, 6, 1), 'store 1': 7, 'store 2': 12},
]

s.plt.bar(
    data=data, order=0,
    x='date', rows_size=2, cols_size=10,
    padding='0,1,0,1',
    x_axis_name='date',
    y_axis_name='revenue / store',
    title='Revenue per store, first half - 2021',
)
```

![Bar chart with padding title and axis names.](/files/iOjWMkuTVbmxte9eyUJZ)

And if you want to show just one variable, for example showing the average height of a thousand trees in the year 2021, you can provide the following data:

```python
data = [
    {'date': 'Jan', 'Height': 3},
    {'date': 'Feb', 'Height': 3.5},
    {'date': 'Mar', 'Height': 4.2},
    {'date': 'Apr', 'Height': 5},
    {'date': 'May', 'Height': 5.8},
    {'date': 'Jun', 'Height': 6.3},
]

s.plt.bar(
    data=data, order=0, x='date', rows_size=2, cols_size=10,
    padding='0,1,0,1', x_axis_name='month', y_axis_name='height (m)',
    title='Evolution: Average Height of 1000 Trees - 2021',
)
```

![Bar chart for one variable, fully customized.](/files/3uRkJ4rQteIH6Jq0VH9J)

## Interesting Usages

* Visualizing survey results: Bar charts are a great way to display the results of a survey. For example, you could use a bar chart to show the percentage of people who answered "yes," "no," or "maybe" to a particular question.

  <figure><img src="/files/7oid3Ifxkd6VsYTc5T6d" alt=""><figcaption><p>Survey results</p></figcaption></figure>
* Comparing data: Bar charts are also useful for comparing data. For example, you could use a bar chart to compare the sales of different products over a given time period.

  <figure><img src="/files/1PL3JSyxISuhmuRgKtRl" alt=""><figcaption><p>Comparative sales of products</p></figcaption></figure>

## Variants

By setting the parameter `variant` to the following values the appearance of the chart can be changed:

{% tabs %}
{% tab title="Clean" %}

<figure><img src="/files/K9WTBXF4XGd92XkeKOPx" alt=""><figcaption><p>variant="clean"</p></figcaption></figure>
{% endtab %}

{% tab title="Minimal" %}

<figure><img src="/files/btuB2344qzCCD9ggR8jM" alt=""><figcaption><p>variant="minimal"</p></figcaption></figure>
{% endtab %}

{% tab title="Thin" %}

<figure><img src="/files/UBSoo35HFrqU3cluKD36" alt=""><figcaption><p>variant="thin"</p></figcaption></figure>
{% endtab %}

{% tab title="Clean Thin" %}

<figure><img src="/files/GznI0qaATTqisMsujbWx" alt=""><figcaption><p>variant="clean thin"</p></figcaption></figure>
{% endtab %}

{% tab title="Minimal Thin" %}

<figure><img src="/files/HTd8FBsW9FQkCQdCSYMf" alt=""><figcaption><p>variant="minimal thin"</p></figcaption></figure>
{% endtab %}

{% tab title="Shadow" %}

<figure><img src="/files/fqWyarFdavCdDZAVfURM" alt=""><figcaption><p>variant="shadow"</p></figcaption></figure>
{% endtab %}

{% tab title="Clean Shadow" %}

<figure><img src="/files/WpoS87cEYKUr537eiQb1" alt=""><figcaption><p>variant="clean shadow"</p></figcaption></figure>
{% endtab %}

{% tab title="Minimal Shadow" %}

<figure><img src="/files/8Kv8vQgvpuYzW4GaAd0I" alt=""><figcaption><p>variant="minimal shadow"</p></figcaption></figure>
{% endtab %}
{% endtabs %}

{% hint style="info" %}

### Featured Content

[Changing the Menu Path](/dev/building-web-app/menu/changing-the-menu-path.md)\
The `menu_path` can be modified.<br>

[Using the Grid](/dev/building-web-app/grid/using-the-grid.md)

It is possible to use any number of rows.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shimoku.com/dev/elements/charts/bar-charts/bar.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
