I wish to plot a scatter plot with no facecolors but with different edgecolors. In other words, colorful circles.

我希望画出一个散点图,没有facecolors,但有不同的edgecolors。换句话说,就是色彩斑斓的圆圈。

I thought I could easily found solution in matplotlib gallery but surprisingly I couldn't. Parameter "edgecolors" does not accept array as values. And manipulate parameter 'c' won't help with edgecolors but facecolors.

我想我可以很容易地在matplotlib画廊找到解决方案,但令人惊讶的是,我做不到。参数“edgecolors”不接受数组作为值。而操纵参数“c”不会对edgecolors有帮助,但对facecolors有帮助。

Here is a link that I thought would be the solution: https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.scatter.html

这里有一个我认为可以解决的链接:https://matplotlib.org/api/_as_gen/matplotlib.axes.scatter.html。

The demo picture at the end of the page seems to have colorful edgecolors! Then I download the script and run it:

页面末尾的演示图片似乎有丰富多彩的edgecolors!然后我下载脚本并运行它:

The edge is still black.

边缘仍然是黑色的。

I am now doing my plot other ways. (since this is not a big matter. This is only a question of interest.) I just wonder how did the demo get the colorful edges.

我现在用其他方法来画。(因为这不是什么大问题。这只是一个有趣的问题。我只是想知道这个演示是如何得到彩色边缘的。

1 个解决方案

#1


0

As others have said the way that the demo script got the colourful edges is that matplotlib 2.0 automatically sets the edge colour of the points in the scatter plot to the provided colour argument.

正如其他人说的那样,演示脚本得到了丰富多彩的边缘,matplotlib 2.0自动设置了散点图中的点的边缘颜色,以提供颜色参数。

If, however, you want to recreate the results of the demo script without updating to mpl 2.0 (though I recommend it) you only need to add an additional keyword parameter to the scatter line as follows

但是,如果您想要在不更新mpl 2.0的情况下重新创建演示脚本的结果(尽管我推荐它),您只需要向散点行添加一个额外的关键字参数,如下所示。

plt.scatter(x, y, s=area, c=colors, alpha=0.5, edgecolors=colors)

And for the sake of completeness you can implement the colourful circle idea that you originally had by faking it. You only need to change the internal colour to white, i.e.

为了完整起见,你可以实现你最初通过伪装它所拥有的色彩斑斓的圆圈。你只需要将内部颜色改为白色,即

plt.scatter(x, y, s=area, c='w', alpha=0.5, edgecolors=colors)

Additionally, you can't use a single float to define the colour for edgecolors as they are doing for the 'c' argument in the demo script so you either need to supply an array of length N that are all specified colours, e.g. ['r', 'g', 'b'], or replace the definition of the colours with

此外,您不能使用一个浮动edgecolors的颜色定义为他们所做的“c”论点的演示脚本,所以你需要提供一个数组的长度N所有指定的颜色,例如[‘r’,‘g’,' b '],或更换颜色的定义

colors = np.random.random((N, p))

where p is either 3 or 4 depending if you want RGB or RGBA colours in the plot. This should produce something like the following plot

其中p为3或4取决于你想要RGB还是RGBA颜色。这应该会产生如下图。

更多相关文章

  1. 球体上的颜色来描绘价值
  2. 如何更改提示颜色?
  3. debain 系统 ll 命令无法使用.目录和文件没有颜色区分解决之道
  4. 背景图像颜色检测与Android油漆。
  5. Android Toolbar返回按钮颜色修改
  6. Android 自定义控件 改变图片颜色来实现类似selector点击更改颜
  7. Android开发笔记——改变字体颜色的三种方法
  8. 更改Edittext光标的颜色与粗细
  9. ## MPAndroidChart-->BarChart-->点击柱颜色改变

随机推荐

  1. 自定义全屏Dialog
  2. Android再次按back键退出
  3. 使一个button无效时变灰
  4. Android开发整理
  5. 在gradle中配置umeng多渠道以及不同的ume
  6. Android 获取View高度宽度
  7. WebViewJavascriptBridge实现js与android
  8. Android常用框架地址
  9. 45个android实例源码
  10. Android之NetworkOnMainThreadException