简体   繁体   English

Polarplot:要绘制的两个列表的不同颜色

[英]Polarplot: different colors for the two list to be plotted

Consider the following code:考虑以下代码:

import numpy as np
from numpy import *
from matplotlib.pyplot import *
import matplotlib.pyplot as plt
from mpmath import *
import random

def graphMesure(listeAlpha,listeBeta):
    # Compute areas and colors
    r = np.asarray([1]*len(listeAlpha)+[0.5]*len(listeBeta))
    colors = np.asarray([0.005]*len(listeAlpha)+[0.2]*len(listeBeta))
    area = 200*r**2

    fig = plt.figure()

    ax = fig.add_subplot(111, projection='polar')
    ax.set_ylim([0,1.25])
    c = ax.scatter(listeAlpha+listeBeta, r, c=colors, s=area, cmap='hsv', alpha=1)

graphMesure([0.5,0.2,0.3],[0.7,0.8,0.2])

All the color on my polarplot are the same.我的 polarplot 上的所有颜色都相同。 I thought that specifying float number for colors like I did would make them of different colors.我认为像我一样为颜色指定浮点数会使它们具有不同的颜色。

How can I for example have the first list given in parameter be plotted as blue and the second one as red ?例如,我如何将参数中给出的第一个列表绘制为蓝色,将第二个绘制为红色?

You need to create valid colors .您需要创建有效的颜色

Your colors looks like this [0.005 0.005 0.005 0.2 0.2 0.2 ] .你的colors看起来像这样[0.005 0.005 0.005 0.2 0.2 0.2 ]

For example:例如:

colors = np.asarray(['r'] * len(listeAlpha) + ['b'] * len(listeBeta))

creates colors with ['r' 'r' 'r' 'b' 'b' 'b'] and gives blue and red dots in your plot:['r' 'r' 'r' 'b' 'b' 'b']创建colors并在你的图中给出蓝色和红色的点:

在此处输入图片说明

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

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