# Violin Plots

Make a violin plot from DataFrame columns, optionally grouped by some other columns. A violin plot is a method for graphically depicting groups of numerical data through their quartiles. See also [Box Plot](/api-reference/plotting/box-plots.md)

## Examples

### Boxplot for a Series Object

{% tabs %}
{% tab title="React" %}
{% code title="App.jsx" %}

```tsx
import { useEffect } from 'react';
import './App.css';
import { Series } from "danfojs-nightly";

function App() {

  useEffect(() => {
       const s = new Series([20, 30, 40, 23, 40, 3, 50, 34, 67])
      s.plot("plot_div").violin()

  }, [])

  return (
    <div className="App">
      <header className="App-header">
        <div id="plot_div"></div>
      </header>
    </div>
  );
}

export default App;
```

{% endcode %}
{% endtab %}

{% tab title="Browser" %}

```html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
    <title>Document</title>
</head>

<body>

    <div id="plot_div"></div>
    <script>

        s = new dfd.Series([20, 30, 40, 23, 40, 3, 50, 34, 67])
        s.plot("plot_div").violin()
         
    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

![](/files/OJAuEkygIjFPGHRfwIsp)

### Box plots on a DataFrame

{% tabs %}
{% tab title="React" %}
{% code title="App.jsx" %}

```tsx
import { useEffect } from 'react';
import './App.css';
import { readCSV } from "danfojs-nightly";

function App() {

  useEffect(() => {
    readCSV(
      "https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv"
    )
      .then((df) => {
        const sub_df = df.loc({ columns: ["Age", "Fare"] });
        sub_df.plot("plot_div").violin();
      })
      .catch((err) => {
        console.log(err);
      });
  }, [])

  return (
    <div className="App">
      <header className="App-header">
        <div id="plot_div"></div>
      </header>
    </div>
  );
}

export default App;
```

{% endcode %}
{% endtab %}

{% tab title="Browser" %}

```html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.2.0/lib/bundle.min.js"></script>
    <title>Document</title>
</head>

<body>

    <div id="plot_div"></div>
    <script>

          dfd.readCSV("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv")
            .then(df => {

                sub_df = df.loc({ columns: ["Age", "Fare"] })
                sub_df.plot("plot_div").violin()

            }).catch(err => {
                console.log(err);
            })

    </script>
</body>

</html>
```

{% endtab %}
{% endtabs %}

![](/files/6ciXZkndQTh2YPOxjxKE)

### Box plot for selected columns in a DataFrame

{% tabs %}
{% tab title="React" %}
{% code title="App.jsx" %}

```tsx
import { useEffect } from 'react';
import './App.css';
import { readCSV } from "danfojs-nightly";

function App() {

  useEffect(() => {
    readCSV(
      "https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv"
    )
      .then((df) => {
        df.plot("plot_div").violin({ config: { x: "Survived", y: "Age" }, layout: { title: "Violin Plot" } });
      })
      .catch((err) => {
        console.log(err);
      });
  }, [])

  return (
    <div className="App">
      <header className="App-header">
        <div id="plot_div"></div>
      </header>
    </div>
  );
}

export default App;
```

{% endcode %}
{% endtab %}

{% tab title="Browser" %}

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://cdn.jsdelivr.net/npm/danfojs-nightly@1.0.2/lib/bundle.js"></script>
    <title>Document</title>
  </head>

  <body>
    <div id="plot_div"></div>

    <div id="plot_div"></div>
    <script>
      dfd
        .readCSV(
          "https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv"
        )
        .then((df) => {
          df.plot("plot_div").violin({ config: { x: "Survived", y: "Age" } });
        })
        .catch((err) => {
          console.log(err);
        });
    </script>
  </body>
</html>
```

{% endtab %}
{% endtabs %}

![](/files/s15ZMTcH6UGxDOZH45lz)

{% hint style="info" %}
To customize your plots, see the [Configuring your plot page](/api-reference/plotting/configuring-your-plots.md)
{% 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://danfo.jsdata.org/api-reference/plotting/violin-plots.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.
