Easy Data Visualization
py_simple.easy_data_visualization
easy_data_visualization aims to simplify data visualization. without requiring users to memorize every chart type or matplotlib function.
get_data_range(data)
Calculates the minimum and maximum values of a numeric data series, providing a quick summary range for data inspection before plotting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
list
|
A list of quantitative (int or float) values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[int | float, int | float]
|
A tuple containing the minimum and maximum values (min, max). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
from py_simple.easy_data_visualization import get_data_range
min_val, max_val = get_data_range([5, 2, 9, 1, 7])
data = [5, 2, 9, 1, 7]
if not data:
raise ValueError("Data series cannot be empty.")
min_val = min(data)
max_val = max(data)
plot_bar_chart(labels, values, title=None, x_label=None, y_label=None)
Displays a bar chart with an optional title and axis labels.
Unlike plot_data, which picks a chart type for you, this function
always draws a bar chart and lets you name the chart and its axes, so
the result is ready to share or screenshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
list[str]
|
The name of each bar (shown on the x-axis). |
required |
values
|
list[int | float]
|
The height of each bar. |
required |
title
|
str
|
Text shown above the chart. Defaults to
|
None
|
x_label
|
str
|
Text shown under the x-axis. Defaults to
|
None
|
y_label
|
str
|
Text shown beside the y-axis. Defaults to
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
The bar chart is rendered directly via |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
from py_simple import plot_bar_chart
plot_bar_chart(
["Mon", "Tue", "Wed"],
[3.5, 2.0, 4.5],
title="My Screen Time",
x_label="Day",
y_label="Hours",
)
import matplotlib.pyplot as plt
labels = ["Mon", "Tue", "Wed"]
values = [3.5, 2.0, 4.5]
fig, ax = plt.subplots()
ax.bar(labels, values)
ax.set_title("My Screen Time")
ax.set_xlabel("Day")
ax.set_ylabel("Hours")
ax.spines[["top", "right"]].set_visible(False)
plt.show()
plot_box_plot(data)
Displays a box-and-whisker plot for a numeric data series.
A box plot shows the middle half of the data, the median, and possible outliers, making it useful for quickly understanding the distribution of a list of numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
list[float]
|
The numeric values to visualize. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
The box plot is rendered directly via |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
from py_simple import plot_box_plot
plot_box_plot([12, 14, 15, 15, 16, 18, 30])
import matplotlib.pyplot as plt
data = [12, 14, 15, 15, 16, 18, 30]
fig, ax = plt.subplots()
ax.boxplot(data)
ax.set_title("Box plot")
plt.show()
plot_data(X, Y=None)
Infers the type of the given data (quantitative or categorical) and automatically plots the most appropriate chart(s) for it, handling the chart-type selection, axis setup, and matplotlib boilerplate every data visualization needs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
list
|
The primary data series to plot. |
required |
Y
|
list
|
A second data series to plot against |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
The chart(s) are rendered directly via |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the inferred type combination of |
ValueError
|
If |
Example
from py_simple import plot_data
plot_data([1, 2, 2, 3, 5, 5, 5, 8])
import matplotlib.pyplot as plt
data = [1, 2, 2, 3, 5, 5, 5, 8]
fig, ax = plt.subplots()
ax.hist(data)
ax.set_title("Histogram")
ax.spines[['top', 'right']].set_visible(False)
plt.show()
plot_heatmap(data, title=None, x_label=None, y_label=None)
Displays a heatmap for a two-dimensional numeric data series.
A heatmap represents values in a grid using color intensity, making it useful for quickly spotting patterns, differences, and high or low values across a two-dimensional dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
list[list[int | float]]
|
A rectangular two-dimensional list containing numeric values. |
required |
title
|
str
|
Text shown above the heatmap. Defaults to
|
None
|
x_label
|
str
|
Text shown under the x-axis. Defaults to
|
None
|
y_label
|
str
|
Text shown beside the y-axis. Defaults to
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
The heatmap is rendered directly via |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
from py_simple import plot_heatmap
plot_heatmap(
[[1, 2, 3], [4, 5, 6], [7, 8, 9]],
title="Example Heatmap",
x_label="Columns",
y_label="Rows",
)
import matplotlib.pyplot as plt
data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
fig, ax = plt.subplots()
image = ax.imshow(data)
fig.colorbar(image, ax=ax)
ax.set_title("Example Heatmap")
ax.set_xlabel("Columns")
ax.set_ylabel("Rows")
plt.show()