# The plot command moves the graph

**URL:** <https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161>\
**Category:** Visualization\
**Tags:** question, plot\
**Created:** [May 31, 2021, 11:16pm UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161 "2021-05-31T23:16:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paolo\_Jara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paolo_jara/32/25685_2.png) [@Paolo\_Jara](https://discourse.julialang.org/u/Paolo_Jara)\
**Post date:** [May 31, 2021, 11:16pm UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161/1 "2021-05-31T23:16:46Z")

</div>

Hello, I’m new programming in Julia. I have two queries regarding the Plots package. (i) Is there a way to integrate the colors generated by “distinguishable\_colors (10)” into the scatter below? (ii) Do you know why the graph is not centered?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/3/639f9dee89346727c2736d10ee5b3f7327346484.png)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 1, 2021, 5:11pm UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161/2 "2021-06-01T17:11:22Z")

</div>

Welcome to the community.  
Please read the guidelines [here](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757) and post a MWE by enclosing the code blocks in triple-backticks, to increase the chances of receiving feedback more swiftly.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [June 1, 2021, 6:54pm UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161/3 "2021-06-01T18:54:26Z")

</div>

Re (i), did you try `color=distinguishablecolors(10)`?

---

<div class="post-metadata">

**Author:** ![Paolo\_Jara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paolo_jara/32/25685_2.png) [@Paolo\_Jara](https://discourse.julialang.org/u/Paolo_Jara)\
**Post date:** [June 1, 2021, 6:55pm UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161/4 "2021-06-01T18:55:44Z")

</div>

Like:

```julia
plot(hola[:,11], hola[:,5], seriestype=:scatter,
group=hola[:,:Region_1], color=[distinguishable_colors(10)]

```

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [June 2, 2021, 6:55am UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161/6 "2021-06-02T06:55:54Z")

</div>

It’s really hard to help you when we don’t know what code you are running or whether it does what you expect.

```julia
plot(rand(10,5); color=distinguishable_colors(5)')

```

produces five line plots, each with a different distinguishable color. Do you want something like that?

---

<div class="post-metadata">

**Author:** ![Paolo\_Jara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paolo_jara/32/25685_2.png) [@Paolo\_Jara](https://discourse.julialang.org/u/Paolo_Jara)\
**Post date:** [June 2, 2021, 2:12pm UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161/7 "2021-06-02T14:12:15Z")

</div>

Thanks, yes it worked. I will be more careful when asking the questions.

```julia
plot(hola[:,11], hola[:,5], seriestype=:scatter, group=hola[:,:Region_1], color=distinguishable_colors(5)', legend=:topleft, markersize=8, alpha=0.6)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/6/1692b868763d0c985ebea8499e0bdc8954125bbd.png)

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [June 9, 2021, 1:41pm UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161/8 "2021-06-09T13:41:33Z")

</div>

Get help! created a minimal reproducible example:

```julia
using Plots

hola = Array{Union{String, Float64}}(undef, 50, 3);

hola[:,1]=["Region_$i" for i in rand(1:4,50)];

hola[:,2:3]=10*rand(50,2);

plot(Float64.(hola[:,2]), Float64.(hola[:,3]), seriestype=:scatter, group=hola[:,1], color=distinguishable_colors(4)', legend=:outertopright, markersize=8, alpha=0.6)

```

![reproex](https://global.discourse-cdn.com/julialang/original/3X/a/e/ae8f90e1c24764313164fe0b10c11b5b995b0a44.jpeg)

---

<div class="post-metadata">

**Author:** ![Paolo\_Jara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paolo_jara/32/25685_2.png) [@Paolo\_Jara](https://discourse.julialang.org/u/Paolo_Jara)\
**Post date:** [June 10, 2021, 4:17am UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161/9 "2021-06-10T04:17:59Z")

</div>

Hello, I have this code that puts the name of all the countries where it corresponds, but if I only want to put the name of only a specific group (for example Region\_1), what would I have to add?

```julia

using Plots, Random
hola_3 = Array{Union{String, Float64}}(undef, 50, 4);
hola_3[:,1]=["Region_$i" for i in rand(1:4,50)];
hola_3[:,2:3]=10*rand(50,2);
hola_3[:,4].=randstring(6);

plot(Float64.(hola_3[:,2]), Float64.(hola_3[:,3]), seriestype=:scatter, group=hola_3[:,1], color=distinguishable_colors(4)', legend=:outertopright, markersize=8, alpha=0.6, series_annotations=text.(hola_3[:,4],8) )

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/a/da99f33ef08ef02ebc8976664a915f1656fcc538.png)

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [June 10, 2021, 4:42am UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161/10 "2021-06-10T04:42:28Z")

</div>

You could use the ternary operator to set the text vector to `nothing` when the first column is not equal to…

But the easier way is to create the texts in a separate call to `annotate!`.

Why do you keep everything in a matrix, by the way? Why not a `names` vector, a `regions` vector etc. Or a `DataFrame`? Julia could make a lot more optimisations if it knew which columns are only `String`s and which are numeric.

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [June 10, 2021, 9:01am UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161/12 "2021-06-10T09:01:14Z")

</div>

```julia
using DataFrames

df = DataFrame(Region = ["Region_$i" for i in rand(1:4,50)], 
hola_1 = 10*rand(50),
hola_2 = 10*rand(50),
hola_4 = randstring(6))

using StatsPlots # Required for the DataFrame user recipe

@df df plot(:hola_1, :hola_2, 
seriestype=:scatter, 
group=:Region, 
color=distinguishable_colors(4)', 
legend=:outertopright, markersize=8, alpha=0.6,
series_annotations=text.([:Region[i] == "Region_1" ? :hola_4[i] : "" for i in 1:50] ,8))

```

How to implement it using names vector, a regions vector?  
Could you please illustrate:  
only today did I know that the DataStructures and NamedArrays packages exist

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 10, 2021, 9:17am UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161/13 "2021-06-10T09:17:39Z")

</div>

@Paolo_Jara, it is recommended to create a new post with new questions, to avoid pilling up queries with no bearing with the OP title. Thanks.

---

<div class="post-metadata">

**Author:** ![Paolo\_Jara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paolo_jara/32/25685_2.png) [@Paolo\_Jara](https://discourse.julialang.org/u/Paolo_Jara)\
**Post date:** [June 12, 2021, 3:32am UTC](https://discourse.julialang.org/t/the-plot-command-moves-the-graph/62161/14 "2021-06-12T03:32:45Z")

</div>

It works for me.

```nohighlight
cantidad=50
hola_4=DataFrame(ILH=rand(cantidad), CIP=rand(cantidad),grupo=["Grupo_$i" for i in rand(1:4,cantidad)],	nombre=[randstring(6) for _ in 1:cantidad])

scatter(hola_4.ILH,hola_4.CIP, group=hola_4.grupo, color=distinguishable_colors(4)')
for i=1:cantidad
	if hola_4[i, "grupo"]=="Grupo_1"
		annotate!(hola_4[i,"ILH"],hola_4[i,"CIP"],text(hola_4[i,"nombre"],:center, 9))
	end
end
	plot!()

```
