简体   繁体   English

matplotlib 图例:散点图颜色不是我所期望的

[英]matplotlib legend: scatterplot colours not what I was expecting

I'm making a scatterplot from some data in a pandas dataframe, which has the columns year , name , ttotal and ftotal .我正在根据 pandas dataframe 中的一些数据制作散点图,其中包含yearnamettotalftotal列。 I'm plotting year against ftotal/ttotal using matplotlib, and attempting to colour each point according to its name, which seems to be working mostly.我正在使用 matplotlib 绘制year与 ftotal ftotal/ttotal ttotal 的图,并尝试根据其名称为每个点着色,这似乎主要工作。

However, I'm trying to get the legend in my matplotlib to match up to the colours in the list competition_colours , but for some reason, four of my labels (marteau, oistrakh_A, oistrakh_B, oistrakh_C) in the legend aren't appearing as the colours I expected.但是,我试图让我的competition_colours中的图例与列表 Competition_colours 中的颜色相匹配,但由于某种原因,图例中的四个标签(marteau、oistrakh_A、oistrakh_B、oistrakh_C)没有显示为我期望的颜色。 Anyone have any ideas why?任何人有任何想法为什么? The code screenshot is below.代码截图如下。

图像

fixed: turns out I needed to put [] around the value of the c parameter in plt.scatter() .固定:原来我需要将[]放在plt.scatter()中的c参数的值周围。

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

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