Я ищу, как создать сюжет с несколькими скриптами и мерами ответа из набора данных с двумя модальностями (время и обработка).Мне удалось построить этот скрипичный сюжет, но я не могу раскрасить каждый ответ на лечение определенным цветом.Я ищу простые вещи: я не хочу раскрашивать края и т. Д.
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy
Lcolor = ['red','green','blue'] # targeted colors per treatment
## create a dataset with 2 columns of two modalities (remark: not the purpose of the question)
a = numpy.random.randn(60,1) # create the random variable "measure"
# create the modalities
Ltime = [1,3]
Ltreatment = [0.2,0.6,0.8]
modalities = [[0.2,1], [0.2,3], [0.6, 1], [0.6, 3], [0.8, 1], [0.8,3]]
tempList = []
for i in modalities:
tempList.extend([i]*10)
NpModLis = numpy.array(tempList)
# create a list of violinplot positions
position = [1.2,1.6, 1.8, 3.2, 3.6, 3.8]
# merging into a 2d-array of modalities and the random variable
DATA = numpy.c_[NpModLis,a]
## Dataset is made of first column: treatment, second column: time of mesure, third column: response measure
# Now I want to plot with violin plot for each time, the three violinplots due to treatment, each violinplot with a color specific to treatment
Lcolors = ['red','green','blue'] # respectively fro treatment 0.2, 0.6, 0.8
fig, ax = plt.subplots(figsize=(9, 4))
data=[]
for i in range(len(Ltime)):
j=Ltime[i]
for k in Ltreatment:
data.append(DATA[numpy.logical_and(DATA[:,0]==k,DATA[:,1]==j)][:,2])
ax.violinplot(data, position) # which isd violinplot(measure of one treatment at one time, position)
plt.show()
спасибо за помощь и прокомментировал ответы, чтобы понять ^^