我有多条测线的数据,我想创建seaborn测线图
每个迭代_值具有:
我有以下代码:
def save_graph(properties):
plt.figure()
for iteration_values in properties.iteration_values:
sns_plot = sns.lineplot(iteration_values.x_values, iteration_values.y_values,
hue=iteration_values.line_title)
plt.xlabel = properties.x_label
plt.ylabel = properties.y_label
plt.title(properties.title, fontsize=20)
plt.ylim(0, 1)
figure.savefig(file_path)
plt.close()
iteration_values = [GraphIterationValues([1, 2, 3], [0.1, 0.2, 0.3], "first line title"),
GraphIterationValues(
[1, 2, 3], [0.2, 0.3, 0.4], "second line title"),
GraphIterationValues(
[1, 2, 3], [0.3, 0.4, 0.5], "third line title"),
GraphIterationValues([1, 2, 3], [0.4, 0.5, 0.6], "fourth line title")]
properties = OutputGraphPropertied(
iteration_values, "x label", "y label", "plot title", "./output.jpeg")
save_graph(properties)
但我得到了一个错误:
ValueError: Could not interpret value `first line title` for parameter `hue`
这些是属性类:
class OutputGraphPropertied:
def __init__(self, graph_iteration_values, x_label, y_label, title, file_path):
self.graph_iteration_values = graph_iteration_values
self.x_label = x_label
self.y_label = y_label
self.title = title
self.file_path = file_path
class GraphIterationValues:
def __init__(self, x_values, y_values, line_title):
self.x_values = x_values
self.y_values = y_values
self.line_title = line_title
要使
hue
正常工作,应立即提供所有数据。另外,hue
应该引用与x和y长度相同的数组,因此对x和y值数组中的每个条目重复行标题下面是对
save_graph
的前几行的可能改编:另一个选项是在同一图形上绘制多个绘图,不使用
hue
,而是设置label
:这将循环当前颜色循环,并创建正确的图例
相关问题 更多 >
编程相关推荐