Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oreo colored text possible in matplotlib?

Is there an easy way to have text (specifically axis-label text) with a white outline color, but black fill color. My axis labels fall over portions of my graph that are in some areas are light and others dark, so some label are obscured.

An easy way to solve this problem would be to set the background color of the axis-label text object.

I find the square boxes distracting and if possible, would prefer that the text itself has an inverse oreo coloring.

Before going down a rabbit hole with this, I thought I would ask if anyone knows a simple way to do this.

Thank you for any thoughts.

like image 349
Matthew Perkins Avatar asked Jan 29 '13 15:01

Matthew Perkins


People also ask

How do I change the font color in MatPlotLib?

MatPlotLib with Python To place the legend, use legend() method with location of the legend and store the returned value to set the color of the text. To set the color of the text, use set_color() method with green color. To display the figure, use show() method.

What fonts are available in MatPlotLib?

Matplotlib can use font families installed on the user's computer, i.e. Helvetica, Times, etc. Font families can also be specified with generic-family aliases like ( {'cursive', 'fantasy', 'monospace', 'sans', 'sans serif', 'sans-serif', 'serif'} ).

How do I specify colors on a MatPlotLib plot?

The usual way to set the line color in matplotlib is to specify it in the plot command. This can either be done by a string after the data, e.g. "r-" for a red line, or by explicitely stating the color argument.


1 Answers

You should be able to pull this off using PathEffects, and ax.(x/y)axis.label or ax.get_(x/y)ticklabels() to get the txt objects.

See the examples here: http://matplotlib.org/examples/pylab_examples/patheffect_demo.html

like image 64
2 revs, 2 users 73% Avatar answered Sep 20 '22 11:09

2 revs, 2 users 73%