Plots.jl icon indicating copy to clipboard operation
Plots.jl copied to clipboard

Change plot border width

Open ronisbr opened this issue 7 years ago • 12 comments

Hi guys!

Is there a way to change the border width of a plot? In PyPlot, I usually do:

blw = 2.5
ax[:spines]["top"][:set_linewidth](blw)
ax[:spines]["bottom"][:set_linewidth](blw)
ax[:spines]["left"][:set_linewidth](blw)
ax[:spines]["right"][:set_linewidth](blw)

ronisbr avatar Sep 20 '17 14:09 ronisbr

Unfortunately, I think currently there is not. This would require a new axis attribute like border_width or axis_width that would have to be implemented for all different backends (for pyplot exactly the way you showed above. If anyone is up for that: border_alpha, border_color and maybe border_style (:solid / :dash / :dot / ...) could be implemented simultaneously.

daschw avatar Sep 20 '17 15:09 daschw

Hi @daschw ,

Thanks for the answer! As a workaround, is there a way to directly access the axes in PyPlot backend so that I can manually run those commands?

ronisbr avatar Sep 20 '17 15:09 ronisbr

Some people have had luck modifying the o field (the Python object) but that is thoroughly undefined. I think as a general rule, Plots is best for intuitive, one-line plotting, whereas for control-every-little-element-plotting it's much better to use PyPlot directly.

mkborregaard avatar Sep 20 '17 16:09 mkborregaard

I'd not be so keen on adding heaps of new attributes to control the border attributes in detail.

mkborregaard avatar Sep 20 '17 16:09 mkborregaard

Ok @mkborregaard , thanks for the answer. I have already tried to modify the o field directly without success. I think I will have to stick with PyPlot instead.

ronisbr avatar Sep 20 '17 16:09 ronisbr

I tried modifying the o field and it can work.

plt = plot(rand(10))
fig = plt.o
ax = fig[:get_axes]()[1]
ax[:spines]["left"][:set_linewidth](20)
PyPlot.draw()

I basically got this from #288 however they do mention that savefig() resets any changes... So I guess as @mkborregaard said it's probably better to use PyPlot directly :(

apalugniok avatar Sep 20 '17 19:09 apalugniok

Hi @apalugniok ,

I was using something similar to what you said. However, the next step was savefig. This explains why I was not seeing the modifications.

I switched back to PyPlot as per @mkborregaard advice. I think this issue can be closed, right?

ronisbr avatar Sep 20 '17 20:09 ronisbr

Let's keep it open.

mkborregaard avatar Sep 20 '17 22:09 mkborregaard

A hacky way to achieve this in Plots could probably be to plot with framestyle = :none and then just draw the axis lines manually like you want them to look.

mkborregaard avatar Sep 20 '17 22:09 mkborregaard

Any update on this?

I am using PGFPlotsX and have the same problem with the plot and legend borders. They are too thick.

RaulDurand avatar Feb 19 '21 15:02 RaulDurand

I'm using GR, and it would be super useful to be able to change the axis width for production ready plots

yanivabir avatar Jul 26 '21 18:07 yanivabir

Gonna give my +1, this is something I'd really like.

Boxylmer avatar Jul 06 '22 04:07 Boxylmer