Skip to content

Latest commit

 

History

History
197 lines (137 loc) · 8.28 KB

File metadata and controls

197 lines (137 loc) · 8.28 KB

Jplotlib.scatter()

The scatter() method in Jplotlib allows you to create 2D scatter plots with ease. This method is designed to visualize datasets using both x-coordinates and y-coordinates, and it offers a convenient ways to generate plots:

Method Signatures:

scatter(double[] xPoints, double[] yPoints):

  • Description: Plots a 2D scatter plot using the provided x-coordinates and y-coordinates.
  • Example usage:
     double[] xCoords = {1.0, 2.0, 3.0, 4.0};
     double[] yCoords = {2.5, 5.1, 3.9, 6.2};
     new Jplotlib.scatter(xCoords, yCoords);

Creating Scatter Plots

In Jplotlib, you can use the scatter() method to draw scatter plots, which are a type of plot that displays individual data points as dots. Scatter plots are useful for visualizing the distribution and relationships between two numerical variables.

The scatter() method requires two arrays of the same length: one for the values of the x-axis and another for the values on the y-axis. Each data point in the scatter plot corresponds to a pair of x and y values from these arrays.

Example Usage:

import io.github.manishdait.jplotlib.Jplotlib;

public class App {
  public static void main(String[] args) {
    double[] x = {5,7,8,7,2,17,2,9,4,11,12,9,6};
    double[] y = {99,86,87,88,111,86,103,87,94,78,77,85,86};

    Jplotlib jplotlib = new Jplotlib();
    jplotlib.scatter(x, y);
    jplotlib.show();
  }
}

In this example, we use the scatter() method to create a scatter plot using x as the x-coordinates and y as the y-coordinates. Each point in the plot represents a pair of x and y values from the given arrays.

scatter_eg1.png

Compare Plots

In Jplotlib, you can create compare plots by using two scatter() methods, allowing you to visualize and compare two datasets side by side. This technique is particularly useful when you want to observe the relationship between two variables across two different conditions or scenarios.

Example Usage:

import io.github.manishdait.jplotlib.Jplotlib;

public class App {
  public static void main(String[] args) {
    double[] x1 = {5,7,8,7,2,17,2,9,4,11,12,9,6};
    double[] x2 = {2,2,8,1,15,8,12,9,7,3,11,4,7,14,12};
    double[] y1 = {99,86,87,88,111,86,103,87,94,78,77,85,86};
    double[] y2 = {100,105,84,105,90,99,90,95,94,100,79,112,91,80,85};

    Jplotlib jplotlib = new Jplotlib();
    jplotlib.scatter(x1, y1);
    jplotlib.scatter(x2, y2);
    jplotlib.show();
  }
}

In this example, we use two scatter() methods to create two separate scatter plots. The first scatter() method creates a scatter plot using x1 as the x-coordinates and y1 as the y-coordinates, and the second scatter() method creates another scatter plot using x2 and y2.

scatter_eg2.png

Colors

In Jplotlib, you have the flexibility to set your own color for each scatter plot using the .color() method. This feature allows you to customize the appearance of individual scatter plots, making it easier to distinguish different datasets or conditions in your visualizations. Similar to plot()..color() you can use LibColor enum of java.awt.Color.

Example Usage:

import io.github.manishdait.jplotlib.Jplotlib;
import io.github.manishdait.jplotlib.defaults.color.LibColor;

public class App {
  public static void main(String[] args) {
    double[] x1 = {5,7,8,7,2,17,2,9,4,11,12,9,6};
    double[] x2 = {2,2,8,1,15,8,12,9,7,3,11,4,7,14,12};
    double[] y1 = {99,86,87,88,111,86,103,87,94,78,77,85,86};
    double[] y2 = {100,105,84,105,90,99,90,95,94,100,79,112,91,80,85};

    Jplotlib jplotlib = new Jplotlib();
    jplotlib.scatter(x1, y1)
      .color(LibColor.SKY.getColor());
    jplotlib.scatter(x2, y2)
    .color(LibColor.PINK.getColor());
    jplotlib.show();
  }
}

In this example, we use the .color(LibColor.SKY.getColor()) argument with the first scatter() method to set the color of the first scatter plot to light_blue. Similarly, we use .color(LibColor.PINK.getColor()) with the second scatter() method to set the color of the second scatter plot to pink.

scatter_eg3.png

For a complete list of available colors from the BaseColor enum, you can refer to the LibColor Enum.

Size

In Jplotlib, you can change the size of the dots in each scatter plot using the .size() argument. This feature allows you to adjust the size of individual data points, making them more visually distinguishable and highlighting specific data values in your scatter plots. It takes value between 1 to 10.

Example Usage:

import io.github.manishdait.jplotlib.Jplotlib;

public class App {
  public static void main(String[] args) {
    double[] x = {5,7,8,7,2,17,2,9,4,11,12,9,6};
    double[] y = {99,86,87,88,111,86,103,87,94,78,77,85,86};
    int[] size = {2,5,1,2,5,1,6,5,1,3,6,8,7};

    Jplotlib jplotlib = new Jplotlib();
    jplotlib.scatter(x, y)
      .size(size);
    jplotlib.show();
  }
}

In this example, we use the .size() argument with both scatter() methods to set the size of the dots for each data point. By customizing the size of each dot, you can emphasize specific data points or highlight patterns in the data, enhancing the overall visual representation of your scatter plots.

scatter_eg4.png

Alpha

In Jplotlib, you can adjust the transparency of the dots in scatter plots using the .alpha() method. This feature allows you to control the opacity of data points, making the scatter plot visually more informative and expressive.

Example Usage:

import io.github.manishdait.jplotlib.Jplotlib;

public class App {
  public static void main(String[] args) {
    double[] x = {5,7,8,7,2,17,2,9,4,11,12,9,6};
    double[] y = {99,86,87,88,111,86,103,87,94,78,77,85,86};
    int[] size = {2,5,1,2,5,1,6,5,1,3,6,8,7};

    Jplotlib jplotlib = new Jplotlib();
    jplotlib.scatter(x, y)
      .size(size)
      .alpha(0.5F);
    jplotlib.show();
  }
}

In this example, we use the .alpha() argument with the scatter() method to set the transparency (opacity) of the dots in the scatter plot. The alphaValue is a float value between 0 and 1, where 0 means completely transparent (invisible) dots, and 1 means completely opaque (fully visible) dots.

By adjusting the transparency of the dots, you can reveal underlying patterns in the data, especially when data points overlap or cluster closely together. It helps in visualizing the density of data points and identifying areas with higher concentration.

scatter_eg5.png

Marker

In Jplotlib, you can change the style of markers for scatter points using the .marker() method. This feature allows you to customize the appearance of individual data points in scatter plots, making it easier to identify different data categories or highlight specific data points.

Example Usage:

import io.github.manishdait.jplotlib.Jplotlib;
import io.github.manishdait.jplotlib.defaults.marker.Marker;

public class App {
  public static void main(String[] args) {
    double[] x1 = {5,7,8,7,2,17,2,9,4,11,12,9,6};
    double[] x2 = {2,2,8,1,15,8,12,9,7,3,11,4,7,14,12};
    double[] y1 = {99,86,87,88,111,86,103,87,94,78,77,85,86};
    double[] y2 = {100,105,84,105,90,99,90,95,94,100,79,112,91,80,85};

    Jplotlib jplotlib = new Jplotlib();
    jplotlib.scatter(x1, y1)
      .marker(Marker.SQUARE);
    jplotlib.scatter(x2, y2);
    jplotlib.show();
  }
}

In this example, we use the .marker(Marker.SQUARE) method with the .scatter() method to set the style of the marker for the scatter points. The Marker.SQUARE value specifies that square markers will be used for each data point in the scatter plot.

scatter_eg6.png

You can use various marker styles, such as Marker.NONE, Marker.CIRCLE, or Marker.SQUARE, to change the appearance of the data points in the scatter plot.

For a complete list of available marker types and more details, you can refer to the Marker Section. Here the difference is that the Marker.NONE will work same as Marker.CIRCLE.