Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.2
0.0.3
2 changes: 2 additions & 0 deletions chartly/chartly.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
BoxPlot,
Contour,
Density,
DotPlot,
Histogram,
LinePlot,
NormalCDF,
Expand Down Expand Up @@ -84,6 +85,7 @@ def __init__(self, args={}):
"line_plot": LinePlot,
"contour": Contour,
"normal_cdf": NormalCDF,
"dotplot": DotPlot,
}

self.subplots = []
Expand Down
55 changes: 55 additions & 0 deletions chartly/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()