# Creating custom tick labels in a plot

**URL:** <https://community.plotly.com/t/creating-custom-tick-labels-in-a-plot/4239>\
**Category:** 📊 Plotly Python\
**Created:** [May 16, 2017, 5:53pm UTC](https://community.plotly.com/t/creating-custom-tick-labels-in-a-plot/4239 "2017-05-16T17:53:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![navajyoth814](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@navajyoth814](https://community.plotly.com/u/navajyoth814)\
**Post date:** [May 16, 2017, 5:53pm UTC](https://community.plotly.com/t/creating-custom-tick-labels-in-a-plot/4239/1 "2017-05-16T17:53:18Z")

</div>

I have been trying to create a contour plot. The data set comprises of 366 units in the X-axis and 216 units in the Y-axis. Hence the axes display values from 0 to 365 and 0 to 215 in the X and Y axes respectively.

1. I want to label the X-axis to display equally spaced names of 12 months. ie., Jan, Feb, …, Dec, and Y-axis to show only 3 points labelled -30, 0 and 30.

2. I want to create a line through the points of maxima.

How can I do these?

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [May 17, 2017, 7:51pm UTC](https://community.plotly.com/t/creating-custom-tick-labels-in-a-plot/4239/2 "2017-05-17T19:51:50Z")

</div>

@navajyoth814 To place the ticklabels as you want, insert in the dict `xaxis` the following key-value pairs:

```
tickvals=[(2*k-1)*hx/2 for k in range(1,13)]
ticktext=['January', 'February', ...]

```

where `hx=366/12.0` was defined before.

For `yaxis` set:

```
tickvals=[k*hy for k in range(3)]
ticktext=[-30, 0, 30]

```

with `hy=266.0/2`.

---

<div class="post-metadata">

**Author:** ![navajyoth814](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@navajyoth814](https://community.plotly.com/u/navajyoth814)\
**Post date:** [May 18, 2017, 4:15am UTC](https://community.plotly.com/t/creating-custom-tick-labels-in-a-plot/4239/3 "2017-05-18T04:15:49Z")

</div>

Thank you much for the reply. It helped!

What I’ve been able to chalk up so far has been added below for your reference.

But, I still have no idea how to proceed with the second problem of creating a line connecting points of maxima in the same contour plot.

 ![](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/1/1968a7eefbac4c1d7f4d964c2418089b89eb8c5c.png)

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [May 18, 2017, 1:55pm UTC](https://community.plotly.com/t/creating-custom-tick-labels-in-a-plot/4239/4 "2017-05-18T13:55:19Z")

</div>

@navajyoth814 Just add one more trace of type ‘scatter’, mode=‘lines’, that defines the line of interest: [https://plot.ly/python/line-charts/](https://plot.ly/python/line-charts/)

---

<div class="post-metadata">

**Author:** ![Soerendip](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Soerendip](https://community.plotly.com/u/Soerendip)\
**Post date:** [November 7, 2019, 12:42am UTC](https://community.plotly.com/t/creating-custom-tick-labels-in-a-plot/4239/5 "2019-11-07T00:42:19Z")

</div>

Again, not enough context in the answers.

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [November 7, 2019, 7:35am UTC](https://community.plotly.com/t/creating-custom-tick-labels-in-a-plot/4239/6 "2019-11-07T07:35:24Z")

</div>

@Soerendip

When you don’t want to display as tick labels the values of your data, then plotly provides a “trick”, namely to set  
`xaxis_tickvals`, `xaxis_ticktext`. The former is the list of new values (positions) at which you want to display the corresponding strings/values in the list `xaxis_ticktext`.

In the above example we had:

```auto
tickvals = [(2*k-1)*hx/2 for k in range(1,13)]
ticktext= [datetime.date(2019, m, 1).strftime('%B') for m in range(1, 13)]

```

where

```auto
tickvals = [15.25, 45.75, 76.25, 106.75, 137.25, 167.75, 198.25, 228.75, 259.25, 289.75, 320.25, 350.75]
ticktext = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

```

For more context 🙂 you can read plotly docs: [https://plot.ly/python/reference/#layout-xaxis-tickvals](https://plot.ly/python/reference/#layout-xaxis-tickvals) .
