Skip to content

Commit 1c03d1d

Browse files
authored
Merge pull request #2 from ManishDait/beta-1.2.0
Mege Beta 1.2.0 to master
2 parents 096b509 + fa8ffcd commit 1c03d1d

File tree

15 files changed

+559
-3
lines changed

15 files changed

+559
-3
lines changed

docs/AREA_PLOT.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+

docs/GETTING_STARTED.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Jplotlib is a Java library that allows you to create 2D line plots, scatter plot
99
- [Creating a Scatter Plot](#creating-a-scatter-plot)
1010
- [Creating a Bar Graph](#creating-a-bar-graph)
1111
- [Creating a Pie Chart](#creating-a-pie-chart)
12+
- [CReating a Area PLot](#creating-a-area-plot)
1213

1314
## Installation
1415

@@ -88,6 +89,19 @@ jplotlib.pie(dataPoints);
8889

8990
More information about pie charts can be found in the [PIE.md](PIE.md) document.
9091

92+
## Creating a Area Plot
93+
94+
To create a 2D area plot using Jplotlib, follow the same steps as above, by using the `areaPlot()` method.
95+
96+
```java
97+
double[] x = {1.0, 2.0, 3.0, 4.0};
98+
double[] y = {2.5, 5.1, 3.9, 6.2};
99+
jplotlib.areaPlot(x, y);
100+
```
101+
102+
You can find more information about scatter plots in the [AREA_PLOT.md](AREA_PLOT.md) document.
103+
104+
91105
That's it! You now have the basic knowledge to create various types of visualizations using Jplotlib. Experiment with different data and customization options to create meaningful plots and charts.
92106

93107

docs/assets/area/area_EG1.png

15.8 KB
Loading

docs/assets/area/area_EG2.png

15.1 KB
Loading

docs/assets/area/area_EG3.png

30 KB
Loading

docs/assets/area/area_EG4.png

21 KB
Loading

docs/assets/area/area_EG5.png

23.6 KB
Loading

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.manishdait</groupId>
88
<artifactId>jplotlib</artifactId>
9-
<version>1.1.0</version>
9+
<version>1.2.0</version>
1010

1111
<name>jplotlib</name>
1212
<url>https://github.com/ManishDait/jplotlib</url>

src/main/java/io/github/manishdait/jplotlib/Jplotlib.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.util.ArrayList;
2828
import java.util.List;
2929

30+
import io.github.manishdait.jplotlib.charts.area.AreaChart;
31+
import io.github.manishdait.jplotlib.charts.area.AreaChartOption;
3032
import io.github.manishdait.jplotlib.charts.bar.BarGraph;
3133
import io.github.manishdait.jplotlib.charts.bar.BarGraphOptions;
3234
import io.github.manishdait.jplotlib.charts.helper.Graph;
@@ -74,7 +76,8 @@ public final class Jplotlib implements
7476
LineChartOptions,
7577
ScatterChartOptions,
7678
BarGraphOptions,
77-
PieChartOptions {
79+
PieChartOptions,
80+
AreaChartOption {
7881

7982
protected Window window;
8083
protected Config axisConfiguration;
@@ -295,4 +298,16 @@ public PieChart pie(double[] dataPoints, String[] labels) {
295298
isPlotable = true;
296299
return pieChart;
297300
}
301+
302+
// Area Chart
303+
304+
@Override
305+
public AreaChart areaPlot(double[] xPoints, double[] yPoints) {
306+
setAxisType(AxisType.PLOT);
307+
setAxisParameters(xPoints, yPoints);
308+
AreaChart areaChart = new AreaChart(new CartesianData(xPoints, yPoints));
309+
graphs.add(areaChart);
310+
isPlotable = true;
311+
return areaChart;
312+
}
298313
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2023 Manish Dait
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package io.github.manishdait.jplotlib.charts.area;
26+
27+
import java.awt.Color;
28+
29+
import io.github.manishdait.jplotlib.charts.helper.Graph;
30+
import io.github.manishdait.jplotlib.data.util.Data;
31+
import io.github.manishdait.jplotlib.internals.util.ChartType;
32+
33+
/**
34+
* The AreaChart class implements the Graph interface and represents a area
35+
* chart.
36+
* It allows plotting area chart using polygon with customizable styles.
37+
*
38+
*/
39+
public class AreaChart implements Graph {
40+
41+
private Data data;
42+
private AreaChartStyle style;
43+
private static final ChartType CHART_TYPE = ChartType.AREA;
44+
45+
/**
46+
* Constructs a AreaChart with the provided data coordinates and initializes
47+
* default style settings.
48+
*
49+
* @param data
50+
* The data coordinates to be plotted on the area chart.
51+
*/
52+
public AreaChart(Data data) {
53+
this.data = data;
54+
this.style = new AreaChartStyle();
55+
}
56+
57+
public Data getData() {
58+
return data;
59+
}
60+
61+
public void setData(Data data) {
62+
this.data = data;
63+
}
64+
65+
public AreaChartStyle getStyle() {
66+
return style;
67+
}
68+
69+
public void setStyle(AreaChartStyle style) {
70+
this.style = style;
71+
}
72+
73+
public static ChartType getChartType() {
74+
return CHART_TYPE;
75+
}
76+
77+
public AreaChart color(Color color) {
78+
style.setColor(color);
79+
return this;
80+
}
81+
82+
public AreaChart alpha(float alpha) {
83+
if (alpha > 1 || alpha < 0) {
84+
alpha = 1;
85+
}
86+
style.setAlpha(alpha);
87+
return this;
88+
}
89+
90+
}

0 commit comments

Comments
 (0)