Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to specify figsize for matplotlib #578

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions hdbscan/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def _select_clusters(self):
def plot(self, leaf_separation=1, cmap='viridis', select_clusters=False,
label_clusters=False, selection_palette=None,
axis=None, colorbar=True, log_size=False,
max_rectangles_per_icicle=20):
max_rectangles_per_icicle=20, plot_size=None):
"""Use matplotlib to plot an 'icicle plot' dendrogram of the condensed tree.

Effectively this is a dendrogram where the width of each cluster bar is
Expand All @@ -285,7 +285,6 @@ def plot(self, leaf_separation=1, cmap='viridis', select_clusters=False,
cmap : string or matplotlib colormap, optional (default viridis)
The matplotlib colormap to use to color the cluster bars.


select_clusters : boolean, optional (default False)
Whether to draw ovals highlighting which cluster
bar represent the clusters that were selected by
Expand All @@ -306,7 +305,6 @@ def plot(self, leaf_separation=1, cmap='viridis', select_clusters=False,
The matplotlib axis to render to. If None then a new axis
will be generated. The rendered axis will be returned.


colorbar : boolean, optional (default True)
Whether to draw a matplotlib colorbar displaying the range
of cluster sizes as per the colormap.
Expand All @@ -315,12 +313,15 @@ def plot(self, leaf_separation=1, cmap='viridis', select_clusters=False,
Use log scale for the 'size' of clusters (i.e. number of
points in the cluster at a given lambda value).


max_rectangles_per_icicle : int, optional (default 20)
To simplify the plot this method will only emit
``max_rectangles_per_icicle`` bars per branch of the dendrogram.
This ensures that we don't suffer from massive overplotting in
cases with a lot of data points.

plot_size : tuple, optional (default None)
Manually specify figsize using call to matplotlib.figsize = plot_size


Returns
-------
Expand All @@ -333,6 +334,9 @@ def plot(self, leaf_separation=1, cmap='viridis', select_clusters=False,
raise ImportError(
'You must install the matplotlib library to plot the condensed tree.'
'Use get_plot_data to calculate the relevant data without plotting.')

if plot_size:
plt.figsize = plot_size

plot_data = self.get_plot_data(leaf_separation=leaf_separation,
log_size=log_size,
Expand Down