简体   繁体   English

需要在图表外使用 matplotlib 散点标记,在条形图的标签中

[英]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 (eg v instead of a real triangle).相反,它们只显示标记的代码字母(例如 v 而不是真正的三角形)。

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.如果它们是我可以在某处找到的 UTF-8 符号,我可以手动将符号添加到条形图图例中,但我无法找到每个标记可能是哪个字符的确切规范。

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.我也在考虑使用.text()和文字 UTF-8 字符,而不是.scatter() ,但是即使我选择带有 fontproperties 的 Unicode 字体,许多符号也不会呈现(显示为正方形),所以我坚持这种方法。

Thanks for the help!谢谢您的帮助!

散点图和条形图

Using Latex is a rather easy solution.使用Latex是一个相当简单的解决方案。 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.如果你需要帮助找出符号的名称,是一个很棒的小网站,它允许你绘制你想要的符号,它会输出 LaTex 名称。

It looks like using Unicode / LaTeX text is the best way to procede, according to this:看起来使用 Unicode / LaTeX 文本是最好的方法,根据这个:

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

I'll add more details as I figure them out.当我弄清楚它们时,我会添加更多细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM