是我使用 matplotlib 创建的子图。是否可以根据预定义的范围对颜色进行编码?我想传递一个附加参数,即电压给函数drawLoadDuration,并定义一个设置颜色的比例(使用if-else构造?)。电压越高,颜色越深。此外,由于某种原因,颜色条的 y 刻度标签未显示。非常欢迎任何线索...谢谢!
import matplotlib.cm
from pylab import *
import numpy as np
f, (ax1, ax2, ax3) = plt.subplots(3, sharex=True, sharey=False)
#other subplots
ax3.set_title('Load Profile')
ax3.patch.set_facecolor('silver')
ax3.grid(True)
cmap= plt.cm.bone_r
barHeight = 3
ticklist = []
def drawLoadDuration(period, starty, opacity):
ax3.broken_barh((period), (starty, barHeight), alpha=opacity, facecolors=cmap(opacity), lw=0.5, zorder=2)
ticklist.append(starty+barHeight/2.0)
return 0
drawLoadDuration([(0, 5), (13, 4), (19, 3), (23, 1)], 3, 0.5) #Fan
drawLoadDuration([(19, 1)], 9, 0.65) #Tube Light
drawLoadDuration([(19, 5)], 15, 0.35) #Bulb
drawLoadDuration([(7, 2), (16, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用seaborn中的分割小提琴图来绘制具有不同范围的两个变量。
这是我到目前为止所做的:
from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np
df1 = pd.read_csv('dummy_metric1.csv')
df2 = pd.read_csv('dummy_metric2.csv')
fig, ax2 = plt.subplots()
sns.set_style('white')
palette1 = 'Set2'
palette2 = 'Set1'
colors_list = ['#78C850', '#F08030', '#6890F0', '#A8B820', '#F8D030', '#E0C068', '#C03028', '#F85888', '#98D8D8']
ax1 = sns.violinplot(y=df1.Value,x=df1.modality,hue=df1.metric, palette=palette1, inner="stick")
xlim = ax1.get_xlim()
ylim = ax1.get_ylim()
for violin in ax1.collections:
bbox = violin.get_paths()[0].get_extents()
x0, y0, width, height = bbox.bounds
violin.set_clip_path(plt.Rectangle((x0, y0), width / 2, height, transform=ax1.transData))
ax1.set_xlim(xlim)
ax1.set_ylim(ylim)
ax1.set_title("dummy")
ax1.set_ylabel("metric1")
ax1.set_xlabel("Modality") …Run Code Online (Sandbox Code Playgroud)