Matplotlib markers must be used outside the chart, in the labels for the histogram

I have a scatter plot that uses six different characters to plot points. For example, the code below shows a dot with a triangle symbol down:

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

Each character represents a different class of object. I need to make a reference to the symbols used in the scatter chart in another chart, a bar chart that explains the proportions of each class in each cluster in the scatter chart.

How can I use bar markers using the symbols used for scatter markers? As you can see in the image below, the labels under each bar should correspond to the markers on the chart, but they are not because I don’t know how to call markers outside the context of the scatter plot. Instead, they simply show the code letter for the marker (for example, v instead of the real triangle).

Ignore the fact that the distorted percent line completely overlaps, which I will fix a separate problem.

It would be nice for me to manually add symbols to the histogram legend if they were UTF-8 symbols that I could find somewhere, but I could not find the exact specification for which each marker can be.

I also consider using .text () with UTF-8 literal characters instead of .scatter (), but many characters will not be displayed (displayed as squares) even when I select a Unicode font with fontproperties, so I take this approach.

Thanks for the help!

scatter plot and bar graphs

+6
source share
2 answers

Using Latex is a fairly simple solution. For instance:

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

And if you need help finding character names, this is a great little website that lets you draw the character you want and it will display LaTex names.

+3
source

Using Unicode / LaTeX text seems to be the best way to handle, according to this:

http://www.mail-archive.com/ matplotlib-users@lists.sourceforge.net /msg19442.html

I will add more details when I find out.

0
source

Source: https://habr.com/ru/post/902819/


All Articles