Skip to content

Commit

Permalink
refactor: Update docs and readme for new impl of Jplotlib.
Browse files Browse the repository at this point in the history
  • Loading branch information
manishdait committed Dec 23, 2023
1 parent 74afb86 commit 9a31bb0
Show file tree
Hide file tree
Showing 59 changed files with 237 additions and 214 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ public class App {
jplotlib.title("Line Plot");
jplotlib.xLabel("xLabel");
jplotlib.yLabel("yLabel");
jplotlib.plot(y).build();
jplotlib.plot(y);
jplotlib.show();

}
}
```
<img src="docs/assets/base_eg1.png" alt="base_eg1.png" width="620px">
<img src="docs/assets/readme_EG1.png" alt="readme_eg1.png" width="620px">

Another Example to draw **MultiLine Plot**

Expand All @@ -59,14 +58,14 @@ public class App {
jplotlib.title("Line Plot");
jplotlib.xLabel("xLabel");
jplotlib.yLabel("yLabel");
jplotlib.plot(y1).build();
jplotlib.plot(y1);
jplotlib.plot(y2);
jplotlib.show();

}
}
```

<img src="docs/assets/base_eg2.png" alt="base_eg2.png" width="620px">
<img src="docs/assets/readme_EG2.png" alt="readme_eg2.png" width="620px">

Learn More about Jplotlib in [GETTING_STARTED.md](docs/GETTING_STARTED.md)

Expand Down
44 changes: 36 additions & 8 deletions docs/BAR.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ public class App {
Jplotlib jplotlib = new Jplotlib();
String[] x = {"A", "B", "C", "D"};
double[] y = {3, 8, 1, 10};
jplotlib.bar(x, y)
.build();
jplotlib.bar(x, y);
jplotlib.show();
}
}
```
In this example, we use the `bar()` method to create a bar graph using `x` as the labels for the x-coordinates and `y` as the y-coordinates. Each bar in the graph represents a category defined by the labels, and its height corresponds to the respective value from `y`.

<img src="assets/bar/bar_eg1.png" alt="bar_eg1.png" width="620px">
<img src="assets/bar/bar_EG1.png" alt="bar_eg1.png" width="620px">

Bar graphs are particularly useful for comparing the values of different categories and displaying discrete data. They are commonly used to visualize categorical data and show how different groups or items compare with each other.

Expand All @@ -40,24 +39,53 @@ In Jplotlib, similar to `.plot()`[.color()](PLOT.md) you can customize the color

```java
import io.github.manishdait.jplotlib.Jplotlib;
import io.github.manishdait.jplotlib.style.color.BaseColor;
import io.github.manishdait.jplotlib.defaults.color.LibColor;

public class App {
public static void main(String[] args) {
Jplotlib jplotlib = new Jplotlib();
String[] x = {"A", "B", "C", "D"};
double[] y = {3, 8, 1, 10};
jplotlib.bar(x, y)
.color(BaseColor.PINK.getColor())
.build();
.color(LibColor.PINK.getColor());
jplotlib.show();
}
}
```

In this example, we use the `.color(BaseColor.PINK.getColor())` method with the `bar()` method to set the color of the bars in the bar graph to pink. You can use the `BaseColor` enum to choose from a variety of predefined colors like `BaseColor.RED`, `BaseColor.GREEN`, `BaseColor`.ORANGE, and more.
In this example, we use the `.color(LibColor.PINK.getColor())` method with the `bar()` method to set the color of the bars in the bar graph to pink. You can use the `LibColor` enum to choose from a variety of predefined colors like `LibColor.RED`, `LibColor.GREEN`, `LibColorColor.ORANGE`, and more.

<img src="assets/bar/bar_eg2.png" alt="bar_eg2.png" width="620px">
<img src="assets/bar/bar_EG2.png" alt="bar_eg2.png" width="620px">

You can also use the java.awt.Color class to specify custom colors using RGB values, like `.color(new Color(255, 0, 0))` for red.

# Jplotlib.barh()

The `barh()` method in `Jplotlib` allows you to create Horizonta; 2D bar graphs. It has all similar features like above `bar()` method.

### Method Signature:

```java
barh(String[] xLabels, double[] yPoints)
```
The `barh()` method requires two arrays: `xLabels` containing labels for the x-coordinates (in String format) and `yPoints` containing the corresponding y-coordinates.

### Example Usage:

```java
import io.github.manishdait.jplotlib.Jplotlib;

public class App {
public static void main(String[] args) {
Jplotlib jplotlib = new Jplotlib();
String[] x = {"A", "B", "C", "D"};
double[] y = {3, 8, 1, 10};
jplotlib.barh(x, y);
jplotlib.show();
}
}
```

In this example, we use the `barh()` method to create a bar graph using `x` as the labels for the x-coordinates and `y` as the y-coordinates. Each bar in the graph represents a category defined by the labels, and its width corresponds to the respective value from `x`.

<img src="assets/bar/bar_EG3.png" alt="bar_eg3.png" width="620px">
46 changes: 0 additions & 46 deletions docs/BASE_COLOR.md

This file was deleted.

37 changes: 0 additions & 37 deletions docs/BASE_STROKE.md

This file was deleted.

8 changes: 4 additions & 4 deletions docs/GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ double[] y = {2.5, 5.1, 3.9, 6.2};
```
4. Plot the data using the plot() method:
```java
jplotlib.plot(x, y).build();
jplotlib.plot(x, y);
```
5. Add optional elements like grid, labels, and title:
```java
Expand All @@ -56,7 +56,7 @@ For more details and additional customization options, you can refer to the [PLO
To create a 2D scatter plot using Jplotlib, follow the same steps as above, but instead of using the `plot()` method, use the `scatter()` method:

```java
jplotlib.scatter(x, y).build();
jplotlib.scatter(x, y);
```

You can find more information about scatter plots in the [SCATTER.md](SCATTER.md) document.
Expand All @@ -69,7 +69,7 @@ To create a 2D bar graph using Jplotlib, follow the same initial steps and then
String[] xLabels = {"A", "B", "C", "D"};
double[] yData = {25.0, 42.0, 30.5, 18.7};

jplotlib.bar(xLabels, yData).build();
jplotlib.bar(xLabels, yData);
```

For more details and options for bar graphs, refer to the [BAR.md](BAR.md) document.
Expand All @@ -83,7 +83,7 @@ To create a 2D pie chart using Jplotlib, follow the same initial steps and then
```java
double[] dataPoints = {35.0, 25.0, 15.0, 25.0};

jplotlib.pie(dataPoints).build();
jplotlib.pie(dataPoints);
```

More information about pie charts can be found in the [PIE.md](PIE.md) document.
Expand Down
47 changes: 47 additions & 0 deletions docs/LIB_COLOR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# LibColor Enum

The `LibColor` enum in Jplotlib provides a set of predefined colors that you can use to customize the appearance of your plots.

### Available LibColor:

- `LibColor.BLUE`
- `LibColor.ORANGE`
- `LibColor.GREEN`
- `LibColor.RED`
- `LibColor.PURPLE`
- `LibColor.BROWN`
- `LibColor.PINK`
- `LibColor.GREY`
- `LibColor.LIME`
- `LibColor.SKY`

### Example Usage:

```java
import io.github.manishdait.jplotlib.Jplotlib;
import io.github.manishdait.jplotlib.defaults.color.LibColor;
import io.github.manishdait.jplotlib.defaults.marker.Marker;

public class App {
public static void main(String[] args) {
double[] y1 = {0, 3, 4, 7};
double[] y2 = {2.5, 5.1, 3.9, 6.2};

Jplotlib jplotlib = new Jplotlib();
jplotlib.plot(y1)
.marker(Marker.CIRCLE)
.markerColor(LibColor.GREEN.getColor());
jplotlib.plot(y2)
.marker(Marker.SQUARE)
.markerColor(Color.MAGENTA);
jplotlib.show();
}
}
```
In this example, we use the `.color(LibColor.BLUE.getColor())` method to set the line color to blue and `.markerColor(LibColor.RED.getColor())` to set marker color red using `LibColor` from Jplotlib. The `LibColor.BLUE` constant provides the predefined blue color and `LibColor.RED` constant provides predefine red color.

<img src="assets/marker/marker_EG2.png" alt="base_stroke_eg1.png" width="620px">

You can use any of the available LibColor constants to customize the color of lines, markers, or other visual elements in your plot according to your preferences.


49 changes: 21 additions & 28 deletions docs/MARKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Currently, Jplotlib provides three marker types:

```java
import io.github.manishdait.jplotlib.Jplotlib;
import io.github.manishdait.jplotlib.style.marker.BaseMarker;
import io.github.manishdait.jplotlib.defaults.marker.Marker;

public class App {
public static void main(String[] args) {
Expand All @@ -28,36 +28,33 @@ public class App {

Jplotlib jplotlib = new Jplotlib();
jplotlib.plot(y1)
.marker(BaseMarker.NONE)
.build();
.marker(Marker.NONE);
jplotlib.plot(y2)
.marker(BaseMarker.CIRCLE)
.build();
.marker(Marker.CIRCLE);
jplotlib.plot(y3)
.marker(BaseMarker.SQUARE)
.build();
.marker(Marker.SQUARE);
jplotlib.show();
}
}
```

In above example we use `.marker(BaseMarker.Circle)` to set marker as circle , `.marker(BaseMarker.Square)` to set marker as square and `.marker(BaseMarker.NONE)` to set no marker, `BaseMarker.NONE` is the default marker style.
In above example we use `.marker(Marker.Circle)` to set marker as circle , `.marker(Marker.Square)` to set marker as square and `.marker(Marker.NONE)` to set no marker, `Marker.NONE` is the default marker style.

<img src="assets/marker/marker_eg1.png" alt="marker_eg1.png" width="620px">
<img src="assets/marker/marker_EG1.png" alt="marker_eg1.png" width="620px">


### Setting Marker Color:

You can customize the color of the markers using the `.markerColor()` method. This method accepts either the `BaseColor` enum or `java.awt.Color`. You can find the available colors in the [BaseColor Enum section](BASE_COLOR.md) below.
You can customize the color of the markers using the `.markerColor()` method. This method accepts either the `LibColor` enum or `java.awt.Color`. You can find the available colors in the [LibColor Enum section](LIB_COLOR.md) below.

### Example Usage:

```java
import java.awt.Color;

import io.github.manishdait.jplotlib.Jplotlib;
import io.github.manishdait.jplotlib.style.color.BaseColor;
import io.github.manishdait.jplotlib.style.marker.BaseMarker;
import io.github.manishdait.jplotlib.defaults.color.LibColor;
import io.github.manishdait.jplotlib.defaults.marker.Marker;

public class App {
public static void main(String[] args) {
Expand All @@ -66,20 +63,18 @@ public class App {

Jplotlib jplotlib = new Jplotlib();
jplotlib.plot(y1)
.marker(BaseMarker.CIRCLE)
.markerColor(BaseColor.GREEN.getColor())
.build();
.marker(Marker.CIRCLE)
.markerColor(LibColor.GREEN.getColor());
jplotlib.plot(y2)
.marker(BaseMarker.SQUARE)
.markerColor(Color.MAGENTA)
.build();
.marker(Marker.SQUARE)
.markerColor(Color.MAGENTA);
jplotlib.show();
}
}
```
In above we use `.markerColor(BaseColor.GREEN.getColor())` method to set the marker color to green using the `BaseColor` enum and `.markerColor(Color.MAGENTA)` from java.awt.Color.
In above we use `.markerColor(LibColor.GREEN.getColor())` method to set the marker color to green using the `LibColor` enum and `.markerColor(Color.MAGENTA)` from java.awt.Color.

<img src="assets/marker/marker_eg2.png" alt="marker_eg2.png" width="620px">
<img src="assets/marker/marker_EG2.png" alt="marker_eg2.png" width="620px">


### Setting Marker Size:
Expand All @@ -90,7 +85,7 @@ To adjust the size of the markers, you can use the `.markerSize()` method, which

```java
import io.github.manishdait.jplotlib.Jplotlib;
import io.github.manishdait.jplotlib.style.marker.BaseMarker;
import io.github.manishdait.jplotlib.defaults.marker.Marker;

public class App {
public static void main(String[] args) {
Expand All @@ -99,20 +94,18 @@ public class App {

Jplotlib jplotlib = new Jplotlib();
jplotlib.plot(y1)
.marker(BaseMarker.CIRCLE)
.markerSize(4)
.build();
.marker(Marker.CIRCLE)
.markerSize(4);
jplotlib.plot(y2)
.marker(BaseMarker.SQUARE)
.markerSize(10)
.build();
.marker(Marker.SQUARE)
.markerSize(10);
jplotlib.show();
}
}
```

In above we use `.markerSize(4)` and `.markerSize(10)` to set marker size and 4 and 10 respectivly.

<img src="assets/marker/marker_eg3.png" alt="marker_eg3.png" width="620px">
<img src="assets/marker/marker_EG3.png" alt="marker_eg3.png" width="620px">

You can use the `.marker()` feature to enhance the visibility of data points in your plots and tailor the markers according to your preferences.
Loading

0 comments on commit 9a31bb0

Please sign in to comment.