All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.tablesaw.plotting.smile.SmileHistogram Maven / Gradle / Ivy

There is a newer version: 0.24.4
Show newest version
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package tech.tablesaw.plotting.smile;

import smile.plot.PlotCanvas;
import tech.tablesaw.api.NumberColumn;

import javax.swing.*;
import java.awt.*;

import static tech.tablesaw.plotting.smile.SmilePlotUtils.*;

/**
 * Simple API for producing basic histogram plots directly from Tablesaw tables and columns
 */
public class SmileHistogram {


    public static PlotCanvas create(String plotTitle, String xTitle, String yTitle, NumberColumn column) {
        PlotCanvas canvas = smile.plot.Histogram.plot(column.asDoubleArray());
        canvas.setForeground(Color.DARK_GRAY);
        canvas.setTitle(plotTitle);
        canvas.setAxisLabel(0, xTitle);
        canvas.setAxisLabel(1, yTitle);
        return canvas;
    }

    public static PlotCanvas create(double[] x, String yTitle) {
        return smile.plot.Histogram.plot(yTitle, x);
    }

    public static void show(double[] x) {
        JFrame frame = getjFrame(600, 400);
        String yTitle = "proportion";
        PlotCanvas canvas = create(x, yTitle);
        canvas.setAxisLabel(1, yTitle);
        frame.add(canvas);
        frame.setVisible(true);
    }

    public static void show(String plotTitle, NumberColumn column) {
        JFrame frame = getjFrame(600, 400);
        PlotCanvas canvas = create(plotTitle, column.name(), "proportion", column);
        frame.add(canvas);
        frame.setVisible(true);
    }

    public static void show(NumberColumn column) {
        JFrame frame = getjFrame(600, 400);
        PlotCanvas canvas = create("", column.name(), "proportion", column);
        frame.add(canvas);
        frame.setVisible(true);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy