需要在图表外的条形图标签中使用matplotlib散布标记 [英] Need to use matplotlib scatter markers outside the chart, in labels for a bar graph

查看:121
本文介绍了需要在图表外的条形图标签中使用matplotlib散布标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个散点图,它使用六个不同的符号来绘制点。例如,下面的代码用向下的三角形符号绘制一个点:

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.

我怎么能条形图的标签是否使用了用于散点图标记的符号?如您在下图中所看到的,每个条形图下面的标签都应该与图表中的标记相对应,但它们并不是那样,因为我不知道如何在散点图的上下文之外召唤这些标记。取而代之的是,它们只是显示标记的代码字母(例如,v而不是真正的三角形)。

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.

如果可以在某处找到UTF-8符号,我可以手动将这些符号添加到条形图图例中就可以了,但是我找不到

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.

我也在研究将 .text()与文字UTF-8字符一起使用,而不是 .scatter(),但是即使我选择具有fontproperties的Unicode字体,许多符号也不会呈现(显示为正方形),所以我坚持

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.

感谢您的帮助!

推荐答案

使用 Latex 是一个非常简单的解决方案。例如:

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$") )

如果需要帮助找出符号名称,请是一个很棒的小网站,它允许您绘制所需的符号,并会输出LaTex名称。

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.

这篇关于需要在图表外的条形图标签中使用matplotlib散布标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆