如何使用Chartify添加多个Y轴以绘制弯头曲线

时间:2018-11-19 19:29:12

标签: python data-visualization unsupervised-learning chartify

我想创建一个折线图,但要使用2个不同的Y轴,并用不同的比例尺来替换这段生成2个图的代码:

ch = chartify.Chart(blank_labels=True)
ch.set_title("Elbow method with Euclidian distance")
ch.plot.line(
    data_frame=df_elbow,
    x_column='K',
    y_column='Distortion',
    line_width=1)
ch.show()

ch = chartify.Chart(blank_labels=True)
ch.set_title("Elbow method with sum of squared errors")
ch.plot.line(
    data_frame=df_elbow,
    x_column='K',
    y_column='SSE',
    line_width=1)
ch.show()

谢谢!

2 个答案:

答案 0 :(得分:0)

更新: 已执行第二个y轴图!参见chartify.examples.chart_second_axis()

旧答案: 目前尚不支持第二个y轴图,但是我将为其添加一个issue。谢谢你的建议!

现在,我建议您退回到Bokeh。 See an example here

答案 1 :(得分:0)

谢谢,这是我在等待图表支持2轴时使用Bokeh图所做的:

import bokeh.plotting
from bokeh.models import LinearAxis, Range1d

ch = chartify.Chart(blank_labels=True)
ch.set_title("Elbow method to find optimal K")
ch.set_subtitle("Euclidian distance (Blue) and sum of squared errors (Red)")

ch.figure.y_range = Range1d(5, 14)
ch.figure.line(x=df_elbow['K'], y=df_elbow['Distortion'], line_width=1, line_color="Blue")
ch.figure.extra_y_ranges = {"sum": Range1d(start=200000, end=1200000)}
ch.figure.add_layout(LinearAxis(y_range_name="sum"), 'right')
ch.figure.line(x=df_elbow['K'], y=df_elbow['SSE'], line_width=1, y_range_name='sum', line_color="Red")
ch.show()