Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to use matplotlib scatter markers outside the chart, in labels for a bar graph

I have a scatter plot that uses six different symbols to plot points. For example, the code below plots a point with the downward-pointing triangle symbol:

my_axis.scatter([x], [y], marker='v')

Each symbol represents a different class of object. I need to make reference to the symbols used in the scatter plot in a different chart, a bar graph which explains the proportions of each class in each cluster in the scatter plot.

How can I have the labels for the bar graphs use the symbols used for the scatter plot markers? As you can see in the image below, the labels under each bar ought to correspond to the markers in the chart, but they don't because I don't know how to summon the markers outside of the context of the scatter plot. Instead, they just show the code letter for the marker (e.g. v instead of a real triangle).

Ignore the fact that the garbled line of percentages is all overlapping, that's a separate issue I will fix.

I would be fine with manually adding the symbols to the bar graph legend if they were UTF-8 symbols I could find somewhere, but I haven't been able to find the exact spec for which character each marker might be.

I am also looking at using .text() with literal UTF-8 characters, instead of .scatter(), but many symbols will not render (show up as squares) even when I choose a Unicode font with fontproperties, so I'm stuck on that approach.

Thanks for the help!

scatter plot and bar graphs

like image 850
mrjf Avatar asked Dec 01 '11 07:12

mrjf


1 Answers

Using Latex is a rather easy solution. For example:

from matplotlib import rc
rc('text', usetex=True)
plt.xticks(ind+width/2., ("$\lozenge$", "$\square$", "$\plus$", "o", "$\bigtriangledown$") )

And if you need help figuring out the names for the symbols, this is a great little website that allows you to draw the symbol you want and it will output the LaTex names.

like image 119
cosmosis Avatar answered Oct 29 '22 16:10

cosmosis