【问题标题】:Polarplot: different colors for the two list to be plottedPolarplot:要绘制的两个列表的不同颜色
【发布时间】:2020-02-01 19:01:17
【问题描述】:

考虑以下代码:

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

我的极坐标图上的所有颜色都是一样的。我认为像我一样为颜色指定浮点数会使它们具有不同的颜色。

例如,如何将参数中给出的第一个列表绘制为蓝色,将第二个列表绘制为红色?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    您需要创建valid colors

    您的colors 看起来像这样[0.005 0.005 0.005 0.2 0.2 0.2 ]

    例如:

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

    ['r' 'r' 'r' 'b' 'b' 'b'] 创建colors 并在你的图中给出蓝色和红色的点:

    【讨论】:

      猜你喜欢
      • 2017-05-23
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 2013-05-05
      • 2012-02-26
      • 1970-01-01
      相关资源
      最近更新 更多