# Buggy code
def calibration_plot(
    fraction_positives, mean_predicted_values, algorithm_names=None, filename=None
):
    assert len(fraction_positives) == len(mean_predicted_values)

    sns.set_style("whitegrid")

    colors = plt.get_cmap("tab10").colors

    num_algorithms = len(fraction_positives)

    plt.figure(figsize=(9, 9))
    plt.grid(which="both")
    plt.grid(which="minor", alpha=0.5)
    plt.grid(which="major", alpha=0.75)

    plt.plot([0, 1], [0, 1], "k:", label="Perfectly calibrated")

    for i in range(num_algorithms):
        # ax1.plot(mean_predicted_values[i], fraction_positives[i],
        #         label=algorithms[i] if algorithm_names is not None and i < len(algorithms) else '')

        # sns.tsplot(mean_predicted_values[i], fraction_positives[i], ax=ax1, color=colors[i])

        assert len(mean_predicted_values[i]) == len(fraction_positives[i])
        order = min(3, len(mean_predicted_values[i] - 1))

        sns.regplot(
            mean_predicted_values[i],
            fraction_positives[i],
            order=order,
            x_estimator=np.mean,
            color=colors[i],
            marker="o",
            scatter_kws={"s": 40},
            label=algorithm_names[i]
            if algorithm_names is not None and i < len(algorithm_names)
            else "",
        )

    ticks = np.linspace(0.0, 1.0, num=11)
    plt.xlim([-0.05, 1.05])
    plt.xticks(ticks)
    plt.xlabel("Predicted probability")
    plt.ylabel("Observed probability")
    plt.ylim([-0.05, 1.05])
    plt.yticks(ticks)
    plt.legend(loc="lower right")
    plt.title("Calibration (reliability curve)")

    plt.tight_layout()
    ludwig.contrib.contrib_command("visualize_figure", plt.gcf())
    if filename:
        plt.savefig(filename)
    else:
        plt.show()


# Traceback (IndexError)
for command, viz_pattern in zip(commands, vis_patterns):
result = subprocess.run(command)
figure_cnt = glob.glob(viz_pattern)

assert 0 == result.returncode
E           AssertionError: assert 0 == 1
E            +  where 1 = CompletedProcess(args=['python', '-m', 'ludwig.visualize', '--visualization', 'calibration_1_vs_all', '--metrics', 'ac...robabilities.npy', '--model_names', 'Model1', 'Model2', '--top_k', '6', '-od', 'results/experiment_run'], returncode=1).returncode
tests/integration_tests/test_visualization.py:1581: AssertionError
----------------------------- Captured stderr call -----------------------------
Traceback (most recent call last):
File "/opt/python/3.6.7/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/opt/python/3.6.7/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/travis/build/uber/ludwig/ludwig/visualize.py", line 3265, in <module>
cli(sys.argv[1:])
File "/home/travis/build/uber/ludwig/ludwig/visualize.py", line 3260, in cli
vis_func(**vars(args))
File "/home/travis/build/uber/ludwig/ludwig/visualize.py", line 623, in calibration_1_vs_all_cli
calibration_1_vs_all(probabilities_per_model, gt, **kwargs)
File "/home/travis/build/uber/ludwig/ludwig/visualize.py", line 2654, in calibration_1_vs_all
filename=filename
File "/home/travis/build/uber/ludwig/ludwig/utils/visualization_utils.py", line 856, in calibration_plot
algorithm_names) else '')
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/seaborn/regression.py", line 810, in regplot
x_jitter, y_jitter, color, label)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/seaborn/regression.py", line 114, in __init__
self.dropna("x", "y", "units", "x_partial", "y_partial")
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/seaborn/regression.py", line 66, in dropna
setattr(self, var, val[not_na])
IndexError: too many indices for array

# Fixed code
def calibration_plot(
    fraction_positives, mean_predicted_values, algorithm_names=None, filename=None
):
    assert len(fraction_positives) == len(mean_predicted_values)

    sns.set_style("whitegrid")

    colors = plt.get_cmap("tab10").colors

    num_algorithms = len(fraction_positives)

    plt.figure(figsize=(9, 9))
    plt.grid(which="both")
    plt.grid(which="minor", alpha=0.5)
    plt.grid(which="major", alpha=0.75)

    plt.plot([0, 1], [0, 1], "k:", label="Perfectly calibrated")

    for i in range(num_algorithms):
        # ax1.plot(mean_predicted_values[i], fraction_positives[i],
        #         label=algorithms[i] if algorithm_names is not None and i < len(algorithms) else '')

        # sns.tsplot(mean_predicted_values[i], fraction_positives[i], ax=ax1, color=colors[i])

        assert len(mean_predicted_values[i]) == len(fraction_positives[i])
        order = min(3, len(mean_predicted_values[i]) - 1)

        sns.regplot(
            mean_predicted_values[i],
            fraction_positives[i],
            order=order,
            x_estimator=np.mean,
            color=colors[i],
            marker="o",
            scatter_kws={"s": 40},
            label=algorithm_names[i]
            if algorithm_names is not None and i < len(algorithm_names)
            else "",
        )

    ticks = np.linspace(0.0, 1.0, num=11)
    plt.xlim([-0.05, 1.05])
    plt.xticks(ticks)
    plt.xlabel("Predicted probability")
    plt.ylabel("Observed probability")
    plt.ylim([-0.05, 1.05])
    plt.yticks(ticks)
    plt.legend(loc="lower right")
    plt.title("Calibration (reliability curve)")

    plt.tight_layout()
    ludwig.contrib.contrib_command("visualize_figure", plt.gcf())
    if filename:
        plt.savefig(filename)
    else:
        plt.show()