Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting axes.linewidth without changing the rcParams global dict

So, it seems one cannot do the following (it raises an error, since axes does not have a set_linewidth method):

axes_style = {'linewidth':5} axes_rect = [0.1, 0.1, 0.9, 0.9]  axes(axes_rect, **axes_style) 

and has to use the following old trick instead:

rcParams['axes.linewidth'] = 5 # set the value globally  ... # some code  rcdefaults() # restore [global] defaults 

Is there an easy / clean way (may be one can set x- and y- axes parameters individually, etc)?

If no, why?

like image 900
mlvljr Avatar asked Mar 31 '10 13:03

mlvljr


People also ask

What are Axis spines?

Axis spines are the lines confining the plot area. Depending on the situation, we may want to remove some (or all) of them, change their color, make them less visible, regulate their width/style, or change their position. In this article, we'll explore some handy approaches for dealing with axis spines.

How do I change the plot style in Matplotlib?

Another way to change the visual appearance of plots is to set the rcParams in a so-called style sheet and import that style sheet with matplotlib. style. use . In this way you can switch easily between different styles by simply changing the imported style sheet.

How do I change the thickness of a line in Matplotlib?

Matplotlib allows you to adjust the line width of a graph plot using the linewidth attribute. If you want to make the line width of a graph plot thinner, then you can make linewidth less than 1, such as 0.5 or 0.25.


2 Answers

  • This answer does not work, as it is explained in the comments. I suggest using spines.
  • As mentioned in a comment by Czechnology, consider changing the ticks too.
import matplotlib.pyplot as plt  fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))  ax1.set_title('Normal spine and ticks') ax2.set_title('Adjusted spine and ticks')  # change each spine separately: # ax.spines['right'].set_linewidth(0.5)  # change all spines for axis in ['top','bottom','left','right']:     ax2.spines[axis].set_linewidth(4)  # increase tick width ax2.tick_params(width=4)  plt.show() 

enter image description here

  • see more about spines at:
    • http://matplotlib.org/api/spines_api.html
    • http://matplotlib.org/examples/pylab_examples/multiple_yaxis_with_spines.html
like image 114
Marcos Alex Avatar answered Sep 18 '22 15:09

Marcos Alex


plt.setp(ax.spines.values(), linewidth=5) 
like image 34
kakty3 Avatar answered Sep 16 '22 15:09

kakty3