# Plots.jl: removing a single axis

**URL:** https://discourse.julialang.org/t/plots-jl-removing-a-single-axis/9897
**Category:** Visualization
**Tags:** plotting, plots
**Created:** [March 22, 2018, 3:49pm UTC](https://discourse.julialang.org/t/plots-jl-removing-a-single-axis/9897 "2018-03-22T15:49:27Z")
**Posts on this page:** 10
**Page:** 1

<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: [March 22, 2018, 3:49pm UTC](https://discourse.julialang.org/t/plots-jl-removing-a-single-axis/9897/1 "2018-03-22T15:49:27Z")

</div>

I’m trying to remove the x axis (i.e., bottom border, x ticks and x labels) from a plot. For the sake of helping the documentation effort, here’s what I tried so far.  
My first guess was:

```julia
plot(x,y,xaxis=nothing)

```

but that removes only the ticks and labels.  
Looking at the [Attributes](http://docs.juliaplots.org/latest/attributes/) page in the documentation, I see that axes have a `bodercolor` attribute, but I couldn’t find info on how to set axis attributes. I tried

```julia
p = plot(x,y)
xaxis!(p,bordercolor="white")

```

but surprisingly, that affects both axes. The documentation seems to hint that I can get some axis object using `p[:xaxis]`, but that doesn’t work either.

Any help would be appreciated.

---

<div class="post-metadata">

### Author: ![tobydriscoll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobydriscoll/32/1843_2.png) [@tobydriscoll](https://discourse.julialang.org/u/tobydriscoll)
#### Post date: [March 23, 2018, 12:00am UTC](https://discourse.julialang.org/t/plots-jl-removing-a-single-axis/9897/2 "2018-03-23T00:00:17Z")

</div>

`plot(...,xaxis=false)` seems to do it for me (with pyplot and plotlyjs, at least).

---

<div class="post-metadata">

### Author: ![Jordan\_Cluts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jordan_cluts/32/13753_2.png) [@Jordan\_Cluts](https://discourse.julialang.org/u/Jordan_Cluts)
#### Post date: [March 23, 2018, 12:14pm UTC](https://discourse.julialang.org/t/plots-jl-removing-a-single-axis/9897/3 "2018-03-23T12:14:03Z")

</div>

I checked and it also works in GR.

---

<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: [March 23, 2018, 2:27pm UTC](https://discourse.julialang.org/t/plots-jl-removing-a-single-axis/9897/4 "2018-03-23T14:27:51Z")

</div>

Works for me too, thanks.  
I’m still wondering how axis attributes are actually set.

---

<div class="post-metadata">

### Author: ![Jordan\_Cluts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jordan_cluts/32/13753_2.png) [@Jordan\_Cluts](https://discourse.julialang.org/u/Jordan_Cluts)
#### Post date: [March 23, 2018, 2:50pm UTC](https://discourse.julialang.org/t/plots-jl-removing-a-single-axis/9897/5 "2018-03-23T14:50:10Z")

</div>

> [@yha](#):
>
> I’m still wondering how axis attributes are actually set.

Are you wondering how they are set under the hood? Or simply how you can set various attributes when you call a plot command? (or modify the axis thereafter).

---

<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: [March 23, 2018, 3:50pm UTC](https://discourse.julialang.org/t/plots-jl-removing-a-single-axis/9897/6 "2018-03-23T15:50:55Z")

</div>

The latter: how to set attributes of axes.  
After some experimenting, I now found out I can do `plot(..., x<attribute_name>=value)` to set an attribute listed in `plotattr(:Axis)` on the x axis, including `xshowaxis=false` to hide the axis (although `xaxis=false` also works in this case). A lot of them don’t do anything, at least on the pyplot backend, but unlike setting some random attribute names they don’t throw an error.  
I think I tried `xforeground_color_border="white"` at some point to hide the axis, but it had no effect.

I’m still not sure what the aliases for axis attributes listed in the documentation are for, since `plot(..., x<alias>=value)` doesn’t work. For example `plot(..., xaxiscolor="yellow")` throws an error.

---

<div class="post-metadata">

### Author: ![Jordan\_Cluts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jordan_cluts/32/13753_2.png) [@Jordan\_Cluts](https://discourse.julialang.org/u/Jordan_Cluts)
#### Post date: [March 23, 2018, 4:09pm UTC](https://discourse.julialang.org/t/plots-jl-removing-a-single-axis/9897/7 "2018-03-23T16:09:49Z")

</div>

The aliases are just different words that set the same attribute. The intent is for people to use whatever they can remember for working on the fly with plots. For example you may not remember that “seriescolor” is the command to set the color of a line in a plot, but because “color” is an alias for “seriescolor” it works just as well.

While the documentation makes it seem like you can do plot(…,x=value) you actually can’t in all cases. Some attributes have individual axis settings (such as lims, xlims, ylims, zlims) but in reality those are different attributes with similar names. So in general you cannot just append an x (or y or z) to the front of an attribute. As a result plot(…,axiscolor=“yellow”) works turning all axes to yellow but there isn’t a corresponding xaxiscolor. If you know the backend you are using, it looks like you are using pyplot, then you can read _all_ of the attributes (or maybe its just those available for animations, at the least its a long list) that that backend supports at the very bottom of [this page](http://docs.juliaplots.org/latest/examples/pyplot/).

---

<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: [March 23, 2018, 8:39pm UTC](https://discourse.julialang.org/t/plots-jl-removing-a-single-axis/9897/8 "2018-03-23T20:39:21Z")

</div>

I’m not sure you understand my point. It’s not about aliases in general, but specifically about aliases for axis properties listed in the documentation.

> [@Jordan\_Cluts](#):
>
> So in general you cannot just append an x (or y or z) to the front of an attribute.

Apparently you can. This throws no error:

```julia
for prop in Plots.attributes(:Axis)
   plot( [1,2], [3,4]; Dict( Symbol(:x,prop) => Plots._axis_defaults[prop] )... )
   plot( [1,2], [3,4]; Dict( Symbol(:y,prop) => Plots._axis_defaults[prop] )... )
   plot( [1,2], [3,4]; Dict( Symbol(:z,prop) => Plots._axis_defaults[prop] )... )
end

```

Passing other string as keys throws. So presumably that is the intended interface, although I don’t see it documented anywhere. And it doesn’t work seem to work with the aliases listed in the documentation.

---

<div class="post-metadata">

### Author: ![daschw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daschw/32/2926_2.png) [@daschw](https://discourse.julialang.org/u/daschw)
#### Post date: [March 27, 2018, 12:58pm UTC](https://discourse.julialang.org/t/plots-jl-removing-a-single-axis/9897/9 "2018-03-27T12:58:45Z")

</div>

You are right @yha, the `x<axisabbribute>` and `x_<axisattribute>` only work for the default attribute names but not for their aliases. So `x_foreground_color_axis = :red` works while `x_axiscolor = :red` does not. I really think it should, though. It would be great if you could open an issue for this.  
Having said that, the most convenient way is probably to use the magic axis argument:  
`plot(rand(10), xaxis = :red, yaxis = ("my y label", :green, font(:orange, 10)))`

EDIT: I just saw, you already opened a related issue.

---

<div class="post-metadata">

### Author: ![Xavier\_Gonzalez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xavier_gonzalez/32/36033_2.png) [@Xavier\_Gonzalez](https://discourse.julialang.org/u/Xavier_Gonzalez)
#### Post date: [September 13, 2022, 6:31pm UTC](https://discourse.julialang.org/t/plots-jl-removing-a-single-axis/9897/10 "2022-09-13T18:31:36Z")

</div>

this does not seem to work for me in CairoMakie
