Skip to content

Commit

Permalink
feat: add plot_ prefix back to plotting methods (#212)
Browse files Browse the repository at this point in the history
Closes #211.

### Summary of Changes

Now that plotting functionality is implemented as methods of `Table` and
`Column`, it makes sense to group them together by prepending `plot_` to
the method names.
  • Loading branch information
lars-reimann authored Apr 19, 2023
1 parent bb6a87f commit e50c3b0
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 32 deletions.
10 changes: 5 additions & 5 deletions docs/tutorials/data_visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"execution_count": null,
"outputs": [],
"source": [
"titanic_numerical.correlation_heatmap()"
"titanic_numerical.plot_correlation_heatmap()"
],
"metadata": {
"collapsed": false,
Expand Down Expand Up @@ -143,7 +143,7 @@
"execution_count": null,
"outputs": [],
"source": [
"titanic_numerical.lineplot(\"survived\", \"fare\")"
"titanic_numerical.plot_lineplot(\"survived\", \"fare\")"
],
"metadata": {
"collapsed": false,
Expand Down Expand Up @@ -176,7 +176,7 @@
"execution_count": null,
"outputs": [],
"source": [
"titanic_numerical.get_column(\"age\").boxplot()"
"titanic_numerical.get_column(\"age\").plot_boxplot()"
],
"metadata": {
"collapsed": false,
Expand All @@ -200,7 +200,7 @@
"execution_count": null,
"outputs": [],
"source": [
"titanic_numerical.get_column(\"fare\").histogram()"
"titanic_numerical.get_column(\"fare\").plot_histogram()"
],
"metadata": {
"collapsed": false,
Expand All @@ -224,7 +224,7 @@
"execution_count": null,
"outputs": [],
"source": [
"titanic_numerical.scatterplot(\"age\", \"fare\")\n"
"titanic_numerical.plot_scatterplot(\"age\", \"fare\")\n"
],
"metadata": {
"collapsed": false,
Expand Down
4 changes: 2 additions & 2 deletions src/safeds/data/tabular/containers/_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def variance(self) -> float:
# Plotting
# ------------------------------------------------------------------------------------------------------------------

def boxplot(self) -> Image:
def plot_boxplot(self) -> Image:
"""
Plot this column in a boxplot. This function can only plot real numerical data.
Expand Down Expand Up @@ -507,7 +507,7 @@ def boxplot(self) -> Image:
buffer.seek(0)
return Image(buffer, ImageFormat.PNG)

def histogram(self) -> Image:
def plot_histogram(self) -> Image:
"""
Plot a column in a histogram.
Expand Down
6 changes: 3 additions & 3 deletions src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ def transform_column(self, name: str, transformer: Callable[[Row], Any]) -> Tabl
# Plotting
# ------------------------------------------------------------------------------------------------------------------

def correlation_heatmap(self) -> Image:
def plot_correlation_heatmap(self) -> Image:
"""
Plot a correlation heatmap for all numerical columns of this `Table`.
Expand Down Expand Up @@ -1020,7 +1020,7 @@ def correlation_heatmap(self) -> Image:
buffer.seek(0)
return Image(buffer, format_=ImageFormat.PNG)

def lineplot(self, x_column_name: str, y_column_name: str) -> Image:
def plot_lineplot(self, x_column_name: str, y_column_name: str) -> Image:
"""
Plot two columns against each other in a lineplot.
Expand Down Expand Up @@ -1070,7 +1070,7 @@ def lineplot(self, x_column_name: str, y_column_name: str) -> Image:
buffer.seek(0)
return Image(buffer, format_=ImageFormat.PNG)

def scatterplot(self, x_column_name: str, y_column_name: str) -> Image:
def plot_scatterplot(self, x_column_name: str, y_column_name: str) -> Image:
"""
Plot two columns against each other in a scatterplot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
from safeds.data.tabular.exceptions import NonNumericColumnError


def test_boxplot_complex() -> None:
def test_plot_boxplot_complex() -> None:
with pytest.raises(NotImplementedError): # noqa: PT012
table = Table.from_dict({"A": [1, 2, complex(1, -2)]})
table.get_column("A").boxplot()
table.get_column("A").plot_boxplot()


def test_boxplot_non_numeric() -> None:
def test_plot_boxplot_non_numeric() -> None:
table = Table.from_dict({"A": [1, 2, "A"]})
with pytest.raises(NonNumericColumnError):
table.get_column("A").boxplot()
table.get_column("A").plot_boxplot()


def test_boxplot_float(monkeypatch: _pytest.monkeypatch) -> None:
def test_plot_boxplot_float(monkeypatch: _pytest.monkeypatch) -> None:
monkeypatch.setattr(plt, "show", lambda: None)
table = Table.from_dict({"A": [1, 2, 3.5]})
table.get_column("A").boxplot()
table.get_column("A").plot_boxplot()


def test_boxplot_int(monkeypatch: _pytest.monkeypatch) -> None:
def test_plot_boxplot_int(monkeypatch: _pytest.monkeypatch) -> None:
monkeypatch.setattr(plt, "show", lambda: None)
table = Table.from_dict({"A": [1, 2, 3]})
table.get_column("A").boxplot()
table.get_column("A").plot_boxplot()
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from safeds.data.tabular.containers import Table


def test_histogram(monkeypatch: _pytest.monkeypatch) -> None:
def test_plot_histogram(monkeypatch: _pytest.monkeypatch) -> None:
monkeypatch.setattr(plt, "show", lambda: None)
table = Table.from_dict({"A": [1, 2, 3]})
table.get_column("A").histogram()
table.get_column("A").plot_histogram()
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from safeds.data.tabular.containers import Table


def test_correlation_heatmap_non_numeric(monkeypatch: _pytest.monkeypatch) -> None:
def test_plot_correlation_heatmap_non_numeric(monkeypatch: _pytest.monkeypatch) -> None:
monkeypatch.setattr(plt, "show", lambda: None)
table = Table.from_dict({"A": [1, 2, "A"], "B": [1, 2, 3]})
table.correlation_heatmap()
table.plot_correlation_heatmap()


def test_correlation_heatmap(monkeypatch: _pytest.monkeypatch) -> None:
def test_plot_correlation_heatmap(monkeypatch: _pytest.monkeypatch) -> None:
monkeypatch.setattr(plt, "show", lambda: None)
table = Table.from_dict({"A": [1, 2, 3.5], "B": [2, 4, 7]})
table.correlation_heatmap()
table.plot_correlation_heatmap()
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from safeds.data.tabular.exceptions import UnknownColumnNameError


def test_scatterplot(monkeypatch: _pytest.monkeypatch) -> None:
def test_plot_lineplot(monkeypatch: _pytest.monkeypatch) -> None:
monkeypatch.setattr(plt, "show", lambda: None)
table = Table.from_dict({"A": [1, 2, 3], "B": [2, 4, 7]})
table.scatterplot("A", "B")
table.plot_lineplot("A", "B")


def test_scatterplot_wrong_column_name() -> None:
def test_plot_lineplot_wrong_column_name() -> None:
table = Table.from_dict({"A": [1, 2, 3], "B": [2, 4, 7]})
with pytest.raises(UnknownColumnNameError):
table.scatterplot("C", "A")
table.plot_lineplot("C", "A")
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from safeds.data.tabular.exceptions import UnknownColumnNameError


def test_lineplot(monkeypatch: _pytest.monkeypatch) -> None:
def test_plot_scatterplot(monkeypatch: _pytest.monkeypatch) -> None:
monkeypatch.setattr(plt, "show", lambda: None)
table = Table.from_dict({"A": [1, 2, 3], "B": [2, 4, 7]})
table.lineplot("A", "B")
table.plot_scatterplot("A", "B")


def test_lineplot_wrong_column_name() -> None:
def test_plot_scatterplot_wrong_column_name() -> None:
table = Table.from_dict({"A": [1, 2, 3], "B": [2, 4, 7]})
with pytest.raises(UnknownColumnNameError):
table.lineplot("C", "A")
table.plot_scatterplot("C", "A")

0 comments on commit e50c3b0

Please sign in to comment.