-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathtest_log_graph.py
More file actions
63 lines (44 loc) · 1.56 KB
/
test_log_graph.py
File metadata and controls
63 lines (44 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import numpy as np
import matplotlib.pyplot as plt
from e2b_charts import chart_figure_to_chart
from e2b_charts.charts import LineChart
def _prep_chart_figure():
# Generate x values
x = np.linspace(0, 100, 100)
# Calculate y values
y = np.exp(x)
# Create the plot
plt.figure(figsize=(10, 6))
plt.plot(x, y, label="y = e^x")
# Set log scale for the y-axis
plt.yscale("log")
# Add labels and title
plt.xlabel("X-axis")
plt.ylabel("Y-axis (log scale)")
plt.title("Chart with Log Scale on Y-axis")
plt.legend()
plt.grid(True)
return plt.gcf()
def test_log_chart():
figure = _prep_chart_figure()
chart = chart_figure_to_chart(figure)
assert chart
assert isinstance(chart, LineChart)
assert chart.title == "Chart with Log Scale on Y-axis"
assert chart.x_label == "X-axis"
assert chart.y_label == "Y-axis (log scale)"
assert chart.x_unit is None
assert chart.y_unit == "log scale"
assert chart.x_scale == "linear"
assert chart.y_scale == "log"
assert all(isinstance(x, float) for x in chart.x_ticks)
assert all(isinstance(y, float) for y in chart.y_ticks)
assert all(isinstance(x, str) for x in chart.x_tick_labels)
assert all(isinstance(y, str) for y in chart.y_tick_labels)
lines = chart.elements
assert len(lines) == 1
line = lines[0]
assert line.label == "y = e^x"
assert len(line.points) == 100
assert all(isinstance(x, tuple) for x in line.points)
assert all(isinstance(x, float) and isinstance(y, float) for x, y in line.points)