Plots.jl: removing a single axis



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:


but that removes only the ticks and labels.
Looking at the 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

p = plot(x,y)

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.


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


I checked and it also works in GR.


Works for me too, thanks.
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).


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.


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.


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.

Apparently you can. This throws no error:

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] )... )

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.


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.