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
29 changes: 9 additions & 20 deletions src/safeds/data/tabular/containers/_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,10 +1011,15 @@ def plot_boxplot(self) -> Image:
buffer.seek(0)
return Image.from_bytes(buffer.read())

def plot_histogram(self) -> Image:
def plot_histogram(self, *, number_of_bins: int = 10) -> Image:
"""
Plot a column in a histogram.

Parameters
----------
number_of_bins:
The number of bins to use in the histogram. Default is 10.

Returns
-------
plot:
Expand All @@ -1026,25 +1031,9 @@ def plot_histogram(self) -> Image:
>>> column = Column("test", [1, 2, 3])
>>> histogram = column.plot_histogram()
"""
import matplotlib.pyplot as plt
import seaborn as sns

fig = plt.figure()
ax = sns.histplot(data=self._data)
ax.set_xticks(ax.get_xticks())
ax.set(xlabel=self.name)
ax.set_xticklabels(
ax.get_xticklabels(),
rotation=45,
horizontalalignment="right",
) # rotate the labels of the x Axis to prevent the chance of overlapping of the labels
plt.tight_layout()

buffer = io.BytesIO()
fig.savefig(buffer, format="png")
plt.close() # Prevents the figure from being displayed directly
buffer.seek(0)
return Image.from_bytes(buffer.read())
from safeds.data.tabular.containers import Table

return Table({self._name: self._data}).plot_histograms(number_of_bins=number_of_bins)

# ------------------------------------------------------------------------------------------------------------------
# Conversion
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.