Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib: Changing the color of an axis

Is there a way to change the color of an axis (not the ticks) in matplotlib? I have been looking through the docs for Axes, Axis, and Artist, but no luck; the matplotlib gallery also has no hint. Any idea?

like image 938
knipknap Avatar asked Dec 30 '09 22:12

knipknap


People also ask

How do you change axis color?

To set the color for X-axis and Y-axis, we can use the set_color() method (Set both the edgecolor and the facecolor). To set the ticks color, use tick_params method for axes. Used arguments are axis ='x' (or y or both) and color = 'red' (or green or yellow or ...etc.)

How do you color a label in Python?

Python Tkinter Color Label We can apply color on the Label widget and Label Text. To color the widget label, the background or bg keyword is used, and to change the text color of the label widget, the foreground or fg keyword is used. In this example, we have a colored label widget and label text.

What does PLT axis () do?

axis() method allows you to set the x and y limits with a single call, by passing a list which specifies [xmin, xmax, ymin, ymax] : In [11]: plt. plot(x, np.


2 Answers

When using figures, you can easily change the spine color with:

ax.spines['bottom'].set_color('#dddddd') ax.spines['top'].set_color('#dddddd')  ax.spines['right'].set_color('red') ax.spines['left'].set_color('red') 

Use the following to change only the ticks:

  • which="both" changes both the major and minor tick colors
ax.tick_params(axis='x', colors='red') ax.tick_params(axis='y', colors='red') 

And the following to change only the label:

ax.yaxis.label.set_color('red') ax.xaxis.label.set_color('red') 

And finally the title:

ax.title.set_color('red') 
like image 116
SaiyanGirl Avatar answered Sep 23 '22 09:09

SaiyanGirl


For the record, this is how I managed to make it work:

fig = pylab.figure() ax  = fig.add_subplot(1, 1, 1) for child in ax.get_children():     if isinstance(child, matplotlib.spines.Spine):         child.set_color('#dddddd') 
like image 45
knipknap Avatar answered Sep 20 '22 09:09

knipknap