# Change my legend plotly python line plot area plot

**URL:** <https://community.plotly.com/t/change-my-legend-plotly-python-line-plot-area-plot/46697>\
**Category:** 📊 Plotly Python\
**Created:** [October 31, 2020, 3:52pm UTC](https://community.plotly.com/t/change-my-legend-plotly-python-line-plot-area-plot/46697 "2020-10-31T15:52:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tati](https://avatars.discourse-cdn.com/v4/letter/t/3be4f8/32.png) [@tati](https://community.plotly.com/u/tati)\
**Post date:** [October 31, 2020, 3:52pm UTC](https://community.plotly.com/t/change-my-legend-plotly-python-line-plot-area-plot/46697/1 "2020-10-31T15:52:26Z")

</div>

Hi everyone,

I created a linear plot with plotly.py.  
Below is my code :

```
import plotly.express as px

fig = px.area(df_CO2_regions, x="year", y="co2_billions_t", color="country",
              labels={'co2_billions_t':'CO2 billions tonnes'})

fig.update_layout(height=500, width=1300, title_text="CO2 emissions by region", title_x = 0.5)

fig.show()

```

and this the plot

 ![Capture d’écran 2020-10-31 à 16.27.59](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/b/b1fea0f4826003671f144a4cfc463604197442bd.png)

In the legend of the colors i would like to delete the word country for each line and write it juste for the title of the legend. Also i would like to show more dates on the x axis.  
Can someone know how to do that ?

Thank you

---

<div class="post-metadata">

**Author:** ![nickest](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/nickest/32/10615_2.png) [@nickest](https://community.plotly.com/u/nickest)\
**Post date:** [November 2, 2020, 4:40pm UTC](https://community.plotly.com/t/change-my-legend-plotly-python-line-plot-area-plot/46697/2 "2020-11-02T16:40:32Z")

</div>

Hi @tati, Yes, you should be able to do something like:

```python
import plotly.express as px

fig = px.area(df_CO2_regions, x="year", y="co2_billions_t", color="country",
              labels={'co2_billions_t':'CO2 billions tonnes'})

fig.update_layout(height=500, width=1300, title_text="CO2 emissions by region", title_x = 0.5)

for tr in fig.select_traces():
    tr['name'] = tr['name'].replace('country = ','')

fig.show()

```

---

<div class="post-metadata">

**Author:** ![nickest](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/nickest/32/10615_2.png) [@nickest](https://community.plotly.com/u/nickest)\
**Post date:** [November 2, 2020, 4:43pm UTC](https://community.plotly.com/t/change-my-legend-plotly-python-line-plot-area-plot/46697/3 "2020-11-02T16:43:19Z")

</div>

To add more dates, you can put this after `fig = px.area...`

```python
fig.update_xaxes(nticks=20)

```

Say if you want 20 dates.

---

<div class="post-metadata">

**Author:** ![tati](https://avatars.discourse-cdn.com/v4/letter/t/3be4f8/32.png) [@tati](https://community.plotly.com/u/tati)\
**Post date:** [November 2, 2020, 5:02pm UTC](https://community.plotly.com/t/change-my-legend-plotly-python-line-plot-area-plot/46697/4 "2020-11-02T17:02:28Z")

</div>

> [@nickest](#):
>
> `fig.update_xaxes(nticks=20)`

Thank you very much it works 🙂
