|
| 1 | +# Jplotlib.areaPlot() |
| 2 | + |
| 3 | +The `areaPlot()` method in the `Jplotlib.areaPlot()` allows you to create 2D area plots with ease. This method is designed to visualize datasets using y-coordinates and x-coordinates: |
| 4 | + |
| 5 | +## Method Signatures |
| 6 | +`areaPlot(double[] xPoints, double[] yPoints)`: |
| 7 | + - Description: Plots a 2D area chart using the given x-coordinates and y-coordinates. |
| 8 | + - Example usage: |
| 9 | + ```java |
| 10 | + double[] xCoords = {1.0, 2.0, 3.0, 4.0}; |
| 11 | + double[] yCoords = {2.5, 5.1, 3.9, 6.2}; |
| 12 | + new Jplotlib.areaPlot(xCoords, yCoords); |
| 13 | + ``` |
| 14 | + |
| 15 | + |
| 16 | +## Area Color |
| 17 | + |
| 18 | +To customize the color of the area in the chart, you can use the `.color()` method available in the Jplotlib library. This method allows you to specify the color using either the `LibColor` enum from Jplotlib or the `java.awt.Color` class. |
| 19 | + |
| 20 | +### Using `LibColor` from Jplotlib: |
| 21 | + |
| 22 | +The `LibColor` enum provides a set of predefined colors that you can use to style the line in your plot. Here's an example of how to use it: |
| 23 | + |
| 24 | +```java |
| 25 | +import io.github.manishdait.jplotlib.Jplotlib; |
| 26 | +import io.github.manishdait.jplotlib.defaults.color.LibColor; |
| 27 | + |
| 28 | +public class App { |
| 29 | + public static void main(String[] args) { |
| 30 | + Jplotlib jplotlib = new Jplotlib(); |
| 31 | + double[] y = {6, 2, 7, 11}; |
| 32 | + double[] x = {1, 2, 3, 4}; |
| 33 | + jplotlib.areaPlot(x, y) |
| 34 | + .color(LibColor.LIME.getColor()); |
| 35 | + jplotlib.show(); |
| 36 | + } |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +In this example, we use the `.color(LibColor.LIME.getColor())` method to set the color of the line to lime. |
| 41 | + |
| 42 | +<img src="assets/area/area_EG1.png" alt="area_eg1.png" width="620px"> |
| 43 | + |
| 44 | +For more information about the `LibColor` enum and the available colors, refer to the [LibColor Enum section](LIB_COLOR.md). |
| 45 | + |
| 46 | + |
| 47 | +### Using `java.awt.Color`: |
| 48 | + |
| 49 | +If you prefer to use the `java.awt.Color` class, you can do so as follows: |
| 50 | + |
| 51 | +```java |
| 52 | +import java.awt.Color; |
| 53 | +import io.github.manishdait.jplotlib.Jplotlib; |
| 54 | + |
| 55 | +public class App { |
| 56 | + public static void main(String[] args) { |
| 57 | + Jplotlib jplotlib = new Jplotlib(); |
| 58 | + double[] y = {6, 2, 7, 11}; |
| 59 | + double[] x = {1, 2, 3, 4}; |
| 60 | + jplotlib.areaPlot(x, y) |
| 61 | + .color(Color.RED); |
| 62 | + jplotlib.show(); |
| 63 | + } |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +In this example, we use the `.color(Color.RED)` method to set the color of the line to red. |
| 68 | + |
| 69 | +<img src="assets/area/area_EG2.png" alt="area_eg2.png" width="620px"> |
| 70 | + |
| 71 | +Whichever method you choose, the `.color()` method allows you to customize the appearance of your line plots with different colors according to your preferences. |
| 72 | + |
| 73 | + |
| 74 | +## Alpha |
| 75 | + |
| 76 | +In Jplotlib, you can adjust the transparency of the area in area plots using the `.alpha()` method. This feature allows you to control the opacity of area, making the area plot visually more informative and expressive. |
| 77 | + |
| 78 | +### Example Usage: |
| 79 | + |
| 80 | +```java |
| 81 | +import io.github.manishdait.jplotlib.Jplotlib; |
| 82 | + |
| 83 | +public class App { |
| 84 | + public static void main(String[] args) { |
| 85 | + double[] x = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; |
| 86 | + double[] y = {99,86,87,88,111,86,103,87,94,78,77,85,86}; |
| 87 | + |
| 88 | + Jplotlib jplotlib = new Jplotlib(); |
| 89 | + jplotlib.areaPlot(x, y) |
| 90 | + .alpha(0.5F); |
| 91 | + jplotlib.show(); |
| 92 | + } |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +In this example, we use the `.alpha()` argument with the areaPlot() method to set the transparency (opacity) of the aarea in the area plot. The `alphaValue` is a float value between 0 and 1, where 0 means completely transparent (invisible) area, and 1 means completely opaque (fully visible) area. |
| 97 | + |
| 98 | +By adjusting the transparency of the area, you can reveal underlying patterns in the data, especially when data points overlap closely together. It helps in visualizing the density of data points and identifying areas with overlaping concentration. |
| 99 | + |
| 100 | +<img src="assets/area/area_EG3.png" alt="area_eg3.png" width="620px"> |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +## Multiples Lines |
| 106 | + |
| 107 | +You can plot as many area chart as you like by simply adding more `Jplotlib.areaPlot()` method calls: |
| 108 | + |
| 109 | +### Example Usage: |
| 110 | + |
| 111 | +```java |
| 112 | +import io.github.manishdait.jplotlib.Jplotlib; |
| 113 | + |
| 114 | +public class App { |
| 115 | + public static void main(String[] args) { |
| 116 | + Jplotlib jplotlib = new Jplotlib(); |
| 117 | + double[] x1 = {0, 1, 2, 3}; |
| 118 | + double[] x2 = {2, 3, 4, 5}; |
| 119 | + double[] y1 = {6, 2, 7, 11}; |
| 120 | + double[] y2 = {3, 8, 1, 10}; |
| 121 | + jplotlib.areaPlot(x1, y1); |
| 122 | + jplotlib.areaPlot(x2, y2); |
| 123 | + jplotlib.show(); |
| 124 | + } |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +In this example, we create two sets of y-coordinates (`y1` and `y2`) and two sets of x-coordinates (`x1` and `x2`) and plot them using two separate `Jplotlib.areaPlot()` method calls. |
| 129 | + |
| 130 | +<img src="assets/area/area_EG4.png" alt="area_eg4.png" width="620px"> |
| 131 | + |
| 132 | +### Example Usage: |
| 133 | + |
| 134 | +```java |
| 135 | +import io.github.manishdait.jplotlib.Jplotlib; |
| 136 | + |
| 137 | +public class App { |
| 138 | + public static void main(String[] args) { |
| 139 | + Jplotlib jplotlib = new Jplotlib(); |
| 140 | + double[] x1 = {0, 1, 2, 3}; |
| 141 | + double[] x2 = {2, 3, 4, 5}; |
| 142 | + double[] y1 = {6, 2, 7, 11}; |
| 143 | + double[] y2 = {3, 8, 1, 10}; |
| 144 | + jplotlib.areaPlot(x1, y1); |
| 145 | + jplotlib.areaPlot(x2, y2).alpha(0.3f); |
| 146 | + jplotlib.show(); |
| 147 | + } |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +In this example, we create two sets of y-coordinates (`y1` and `y2`) similar to above example but with alpha. |
| 152 | + |
| 153 | +<img src="assets/area/area_EG5.png" alt="area_eg5.png" width="620px"> |
| 154 | + |
| 155 | + |
0 commit comments