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

Include option for saving plots as files #43

Open
wants to merge 3 commits into
base: main
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
82 changes: 52 additions & 30 deletions CLUEstering/CLUEstering.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,17 +762,19 @@ def output_df(self) -> pd.DataFrame:
return self.clust_prop.output_df


def input_plotter(self, plot_title: str = '', title_size: float = 16,
x_label: str = 'x', y_label: str = 'y', z_label: str = 'z',
label_size: float = 16, pt_size: float = 1, pt_colour: str = 'b',
grid: bool = True, grid_style: str = '--', grid_size: float = 0.2,
x_ticks=None, y_ticks=None, z_ticks=None,
def input_plotter(self, filepath: Union[str, None] = None, plot_title: str = '',
title_size: float = 16, x_label: str = 'x', y_label: str = 'y',
z_label: str = 'z', label_size: float = 16, pt_size: float = 1,
pt_colour: str = 'b', grid: bool = True, grid_style: str = '--',
grid_size: float = 0.2, x_ticks=None, y_ticks=None, z_ticks=None,
**kwargs) -> None:
"""
Plots the points in input.

Parameters
----------
filepath : string, optional
The path to the file where the plot should be saved.
plot_title : string, optional
Title of the plot.
title_size : float, optional
Expand Down Expand Up @@ -842,7 +844,10 @@ def input_plotter(self, plot_title: str = '', title_size: float = 16,
if y_ticks is not None:
plt.yticks(y_ticks)

plt.show()
if filepath is not None:
plt.savefig(filepath)
else:
plt.show()
elif self.clust_data.n_dim == 2:
plt.scatter(cartesian_coords[0],
cartesian_coords[1],
Expand All @@ -866,7 +871,10 @@ def input_plotter(self, plot_title: str = '', title_size: float = 16,
if y_ticks is not None:
plt.yticks(y_ticks)

plt.show()
if filepath is not None:
plt.savefig(filepath)
else:
plt.show()
else:
fig = plt.figure()
ax_ = fig.add_subplot(projection='3d')
Expand Down Expand Up @@ -896,14 +904,17 @@ def input_plotter(self, plot_title: str = '', title_size: float = 16,
if z_ticks is not None:
ax_.set_zticks(z_ticks)

plt.show()

def cluster_plotter(self, plot_title: str = '', title_size: float = 16,
x_label: str = 'x', y_label: str = 'y', z_label: str = 'z',
label_size: float = 16, outl_size: float = 10, pt_size: float = 10,
seed_size: float = 25, grid: bool = True, grid_style: str = '--',
grid_size: float = 0.2, x_ticks=None, y_ticks=None, z_ticks=None,
**kwargs) -> None:
if filepath is not None:
plt.savefig(filepath)
else:
plt.show()

def cluster_plotter(self, filepath: Union[str, None] = None, plot_title: str = '',
title_size: float = 16, x_label: str = 'x', y_label: str = 'y',
z_label: str = 'z', label_size: float = 16, outl_size: float = 10,
pt_size: float = 10, seed_size: float = 25, grid: bool = True,
grid_style: str = '--', grid_size: float = 0.2, x_ticks=None,
y_ticks=None, z_ticks=None, **kwargs) -> None:
"""
Plots the clusters with a different colour for every cluster.

Expand All @@ -912,30 +923,32 @@ def cluster_plotter(self, plot_title: str = '', title_size: float = 16,

Parameters
----------
filepath : string, optional
The path to the file where the plot should be saved.
plot_title : string, optional
Title of the plot
Title of the plot.
title_size : float, optional
Size of the plot title
Size of the plot title.
x_label : string, optional
Label on x-axis
Label on x-axis.
y_label : string, optional
Label on y-axis
Label on y-axis.
z_label : string, optional
Label on z-axis
Label on z-axis.
label_size : int, optional
Fontsize of the axis labels
Fontsize of the axis labels.
outl_size : int, optional
Size of the outliers in the plot
Size of the outliers in the plot.
pt_size : int, optional
Size of the points in the plot
Size of the points in the plot.
seed_size : int, optional
Size of the seeds in the plot
Size of the seeds in the plot.
grid : bool, optional
f true displays grids in the plot
f true displays grids in the plot.
grid_style : string, optional
Style of the grid
Style of the grid.
grid_size : float, optional
Linewidth of the plot grid
Linewidth of the plot grid.
x_ticks : list, optional
List of ticks for the x axis.
y_ticks : list, optional
Expand Down Expand Up @@ -994,7 +1007,10 @@ def cluster_plotter(self, plot_title: str = '', title_size: float = 16,
if y_ticks is not None:
plt.yticks(y_ticks)

plt.show()
if filepath is not None:
plt.savefig(filepath)
else:
plt.show()
elif self.clust_data.n_dim == 2:
data = {'x0': cartesian_coords[0],
'x1': cartesian_coords[1],
Expand Down Expand Up @@ -1029,7 +1045,10 @@ def cluster_plotter(self, plot_title: str = '', title_size: float = 16,
if y_ticks is not None:
plt.yticks(y_ticks)

plt.show()
if filepath is not None:
plt.savefig(filepath)
else:
plt.show()
else:
data = {'x0': cartesian_coords[0],
'x1': cartesian_coords[1],
Expand Down Expand Up @@ -1071,7 +1090,10 @@ def cluster_plotter(self, plot_title: str = '', title_size: float = 16,
if z_ticks is not None:
ax_.set_zticks(z_ticks)

plt.show()
if filepath is not None:
plt.savefig(filepath)
else:
plt.show()

def to_csv(self, output_folder: str, file_name: str) -> None:
"""
Expand Down
Loading