# How to plot percentile distributions?

**URL:** <https://discuss.elastic.co/t/how-to-plot-percentile-distributions/231303>\
**Category:** Kibana\
**Created:** [May 6, 2020, 9:26am UTC](https://discuss.elastic.co/t/how-to-plot-percentile-distributions/231303 "2020-05-06T09:26:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrzejo](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@andrzejo](https://discuss.elastic.co/u/andrzejo)\
**Post date:** [May 6, 2020, 9:26am UTC](https://discuss.elastic.co/t/how-to-plot-percentile-distributions/231303/1 "2020-05-06T09:26:44Z")

</div>

I'm trying to create a latency percentile distribution plot, like the one here: [https://hdrhistogram.github.io/HdrHistogram/plotFiles.html](https://hdrhistogram.github.io/HdrHistogram/plotFiles.html)

But I cannot find a good way to do this, any ideas?

Details:

- My source data in ES a number of records for each measurement containing a data\_source field and a value field, e.g. {A, 24}, {A, 43}, {B,17}
- I would like split the series by data\_source and calculate percentiles of their values
- This data I would like to then plot in such a way the percentile, e.g. 99%, is on the X axis and the actual value at that percentile, e.g 43, is on the Y axis
- I tried the standard visualization (my best effort pasted below), timelion (only supports time-based X axis), and Vega (this has potential I think, but is too complex/undocumented for me to figure out...)

The best I could come up with is pasted below, but this does not work very well, because I cannot set the X axis to consist of percentiles:

```auto
{
  "title": "Bench: Parse Total [us]",
  "type": "line",
  "params": {
    "addLegend": true,
    "addTimeMarker": false,
    "addTooltip": true,
    "categoryAxes": [
      {
        "id": "CategoryAxis-1",
        "labels": {
          "show": false,
          "truncate": 100
        },
        "position": "bottom",
        "scale": {
          "type": "linear"
        },
        "show": false,
        "style": {},
        "title": {},
        "type": "category"
      }
    ],
    "grid": {
      "categoryLines": false,
      "style": {
        "color": "#eee"
      },
      "valueAxis": null
    },
    "legendPosition": "right",
    "seriesParams": [
      {
        "data": {
          "id": "1",
          "label": "Average timing_ParseTotalUs"
        },
        "drawLinesBetweenPoints": true,
        "mode": "normal",
        "show": "true",
        "showCircles": false,
        "type": "line",
        "valueAxis": "ValueAxis-1",
        "interpolate": "linear"
      }
    ],
    "times": [],
    "type": "line",
    "valueAxes": [
      {
        "id": "ValueAxis-1",
        "labels": {
          "filter": false,
          "rotate": 0,
          "show": true,
          "truncate": 100
        },
        "name": "LeftAxis-1",
        "position": "left",
        "scale": {
          "mode": "normal",
          "type": "linear"
        },
        "show": true,
        "style": {},
        "title": {
          "text": "Average timing_ParseTotalUs"
        },
        "type": "value"
      }
    ]
  },
  "aggs": [
    {
      "id": "1",
      "enabled": true,
      "type": "avg",
      "schema": "metric",
      "params": {
        "field": "timing_ParseTotalUs"
      }
    },
    {
      "id": "2",
      "enabled": true,
      "type": "terms",
      "schema": "segment",
      "params": {
        "field": "timing_ParseTotalUs",
        "size": 1000,
        "order": "desc",
        "orderBy": "1",
        "otherBucket": false,
        "otherBucketLabel": "Other",
        "missingBucket": false,
        "missingBucketLabel": "Missing"
      }
    },
    {
      "id": "3",
      "enabled": true,
      "type": "terms",
      "schema": "group",
      "params": {
        "field": "logFilePath",
        "size": 100,
        "order": "desc",
        "orderBy": "_key",
        "otherBucket": false,
        "otherBucketLabel": "Other",
        "missingBucket": false,
        "missingBucketLabel": "Missing"
      }
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [May 11, 2020, 4:07pm UTC](https://discuss.elastic.co/t/how-to-plot-percentile-distributions/231303/2 "2020-05-11T16:07:34Z")

</div>

Why doesn't it work with a line chart? can you post a screenshot? (a query like this is really hard to understand from a visualization point of view)

---

<div class="post-metadata">

**Author:** ![andrzejo](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@andrzejo](https://discuss.elastic.co/u/andrzejo)\
**Post date:** [May 12, 2020, 12:58pm UTC](https://discuss.elastic.co/t/how-to-plot-percentile-distributions/231303/3 "2020-05-12T12:58:00Z")

</div>

Hi Marius,

Here is a screenshot, as you can see there are 2 issues:

- The X axis is overcrowded with labels showing the latency values, and there is no good way to adjust this. Ideally, it should be a histogram-like axis showing percentiles like 99%, etc.
- When you get more series on the diagram, you start losing data on the individual lines, as it seems the number of data points is decided for all the lines together.

Btw. the code pasted above is a view definition copied from Kibana - hopefully it should be possible for you to import the view and reproduce on your local instance.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/7/a7edeeb99d189585da0de998b08c9438afccb362.png)

---

<div class="post-metadata">

**Author:** ![andrzejo](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@andrzejo](https://discuss.elastic.co/u/andrzejo)\
**Post date:** [May 20, 2020, 2:44pm UTC](https://discuss.elastic.co/t/how-to-plot-percentile-distributions/231303/4 "2020-05-20T14:44:46Z")

</div>

I managed to get this working with a custom Vega script.

Would be great though to get this officially supported someday, as percentile plots are a de facto standard for benchmark analysis.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 17, 2020, 2:44pm UTC](https://discuss.elastic.co/t/how-to-plot-percentile-distributions/231303/5 "2020-06-17T14:44:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
