简体   繁体   中英

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. 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 ] .

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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