From 909eb13357d47f5e761d804f73f43f83b48915ae Mon Sep 17 00:00:00 2001 From: Azendae Popo Date: Wed, 30 Oct 2024 11:18:46 -0400 Subject: [PATCH 1/2] Adds DotPlot to Charlty --- chartly/chartly.py | 2 ++ chartly/charts.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/chartly/chartly.py b/chartly/chartly.py index 770c7ea..47cb6ba 100644 --- a/chartly/chartly.py +++ b/chartly/chartly.py @@ -24,6 +24,7 @@ BoxPlot, Contour, Density, + DotPlot, Histogram, LinePlot, NormalCDF, @@ -84,6 +85,7 @@ def __init__(self, args={}): "line_plot": LinePlot, "contour": Contour, "normal_cdf": NormalCDF, + "dotplot": DotPlot, } self.subplots = [] diff --git a/chartly/charts.py b/chartly/charts.py index e6ce274..a0b7b25 100644 --- a/chartly/charts.py +++ b/chartly/charts.py @@ -28,6 +28,7 @@ import seaborn as sns from matplotlib.colors import LinearSegmentedColormap from matplotlib.patches import Rectangle +from matplotlib.ticker import MaxNLocator from scipy.stats import norm from .base import CustomizePlot, Plot @@ -614,3 +615,57 @@ def __call__(self): hatches=[self.customs["pattern"]], alpha=self.customs["alpha"], ) + + +class DotPlot(Plot, CustomizePlot): + """Class to plot a dot plot. + + :param dict args: the master dictionary containing the required fields. + + Required Keys + - data: the data to plot + + Optional Keys + - customs: the plot's customization + - axes_labels: the axes labels + + Available Customizations + - color: the color of the dot plot, default is "black" + """ + + def __init__(self, args): + """Initialize the DotPlot Class.""" + # Get the arguments + self.args = args + + # Extract the customs + customs_ = self.args.get("customs", {}) + super().__init__(self.args) + CustomizePlot.__init__(self, customs_) + + def defaults(self): + return {"color": "black", "num_bins": 10} + + def __call__(self): + """Plot a dot plot""" + # Define x and y lists + x, y = [], [] + + # Get the number of dots for each column + nbins = self.customs["num_bins"] + counts, bins = np.histogram(self.data, bins=nbins) + + # Create the x and y lists + for i in range(nbins): + x.extend([bins[i]] * counts[i]) + y.extend(range(1, counts[i] + 1)) + + # Plot the dots + self.ax.scatter(x, y, color=self.customs["color"]) + + # Restrict the y ticks to only integers + self.ax.yaxis.set_major_locator(MaxNLocator(integer=True)) + + # label the axes + self.axes_labels["show_legend"] = False + self.label_axes() From 69ea04a3b6d1a047d23112293c738cdb8771b48f Mon Sep 17 00:00:00 2001 From: Azendae Popo Date: Wed, 30 Oct 2024 11:19:06 -0400 Subject: [PATCH 2/2] updates version file --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 4e379d2..bcab45a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.2 +0.0.3