# Plot Labelling

**URL:** <https://discourse.julialang.org/t/plot-labelling/39632>\
**Category:** New to Julia\
**Tags:** question, visualization\
**Created:** [May 17, 2020, 12:02pm UTC](https://discourse.julialang.org/t/plot-labelling/39632 "2020-05-17T12:02:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Longblackcoffee](https://avatars.discourse-cdn.com/v4/letter/l/a5b964/32.png) [@Longblackcoffee](https://discourse.julialang.org/u/Longblackcoffee)\
**Post date:** [May 17, 2020, 12:02pm UTC](https://discourse.julialang.org/t/plot-labelling/39632/1 "2020-05-17T12:02:42Z")

</div>

Hi everyone,

I’m trying to make a graph of covid-19 case numbers in 3 countries. I’m having trouble with getting the labels to cooperate. Unlike what’s shown below, I want something like blue: AUS, orange: UK, etc…

![cases](https://global.discourse-cdn.com/julialang/original/3X/c/9/c9a36237769dbc9113f61d90b664741896a671af.png)

This is my code right now (‘Aus\_data’, ‘UK\_data’, ‘US\_data’ and ‘dates’ are variables from data):

```julia
country_list = DataFrame(AUS = Aus_data, UK = UK_data, US = US_data);
p = plot()
for col in eachcol(country_list)
      plot!(dates, col,
      xticks = dates[1:5:end],
      xrotation = 45,
      leg=:topleft,
      m=:o,
      label = [names(country_list)],
      xlabel = "Date",
      ylabel = "Confirmed Cases",
      title = "Confirmed COVID-19 Cases")
end
p

```

Sorry if this is a trivial question - I’m new to Julia, and thank you for your time!

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [May 17, 2020, 12:30pm UTC](https://discourse.julialang.org/t/plot-labelling/39632/2 "2020-05-17T12:30:59Z")

</div>

When you set `label = [names(country_list)]` in your loop you get the full list of names back. You only want the name of one column, which you can’t extract from the column itself if you iterate over `eachcol`, as that only returns the coluns itself without the name.

You could iterate over `for (name, col) in zip(names(country_list), eachcol(country_list))` and then use `label = name`

---

<div class="post-metadata">

**Author:** ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Post date:** [May 17, 2020, 12:31pm UTC](https://discourse.julialang.org/t/plot-labelling/39632/3 "2020-05-17T12:31:20Z")

</div>

Well the first problem I see is that you input to label, “names(country\_list)” isnot indexed into, meaning that you pass all column names to the label for each loop, explaining your result. So you need to use an updating index to access the correct column-name.

But I would do this by simply calling plot(x-vals, y-vals) and use plot! for the following datasets, adding the appropriate label for each. You can then add modifications like ticks and x/y-labels with their own modifier-commands (like “xticks! ()”), or include them in the first call to “plot()”

---

<div class="post-metadata">

**Author:** ![Longblackcoffee](https://avatars.discourse-cdn.com/v4/letter/l/a5b964/32.png) [@Longblackcoffee](https://discourse.julialang.org/u/Longblackcoffee)\
**Post date:** [May 17, 2020, 12:54pm UTC](https://discourse.julialang.org/t/plot-labelling/39632/4 "2020-05-17T12:54:40Z")

</div>

> [@nilshg](#):
>
> for (name, col) in zip(names(country\_list), eachcol(country\_list))

I didn’t know that was a thing, thank you so much, I learnt something new today!

---

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [May 17, 2020, 1:49pm UTC](https://discourse.julialang.org/t/plot-labelling/39632/5 "2020-05-17T13:49:44Z")

</div>

You can also plot this without a loop

```julia
dates = -4:5
country_list = DataFrame(AUS = rand(10), UK = rand(10), US = rand(10))
plot(dates, eachcol(country_list), 
     labels = hcat(names(country_list)...))

```
