|
1 | 1 | import plotly.graph_objects as go
|
2 | 2 | import numpy as np
|
3 | 3 |
|
4 | | -np.random.seed(42) |
| 4 | +def create_line_chart(x_data, y_data): |
| 5 | + fig = go.Figure(data=go.Scatter(x=x_data, y=y_data)) |
5 | 6 |
|
6 | | -# declaring size of arr |
7 | | -size = 7 |
| 7 | + # Modifying the tickangle of the xaxis, and adjusting width and height of the image |
| 8 | + fig.layout.template = 'plotly_dark' |
| 9 | + fig.update_layout( |
| 10 | + title='Line Chart', |
| 11 | + xaxis_title='X Axis Title', |
| 12 | + yaxis_title='Y Axis Title', |
| 13 | + xaxis_tickangle=-45, |
| 14 | + autosize=False, |
| 15 | + width=600, |
| 16 | + height=600, |
| 17 | + margin=dict(l=50, r=50, b=100, t=100, pad=4) |
| 18 | + ) |
| 19 | + fig.show() |
8 | 20 |
|
9 | | -x=np.arange(10) |
10 | | -y=x**2 |
| 21 | +if__name__=="__main__": |
| 22 | +np.random.seed(42) |
11 | 23 |
|
12 | | -fig = go.Figure(data=go.Scatter(x=x, y=x**2)) |
| 24 | + # Generating sample data |
| 25 | + x_data = np.arange(10) |
| 26 | + y_data = x_data ** 2 |
13 | 27 |
|
14 | | -# Modifying the tickangle of the xaxis, and adjusting width and height of the image |
15 | | -fig.layout.template = 'plotly_dark' |
16 | | -fig.update_layout( |
17 | | - title='Line Chart', |
18 | | - xaxis_title='X Axis Title', |
19 | | - yaxis_title='Y Axis Title', |
20 | | - xaxis_tickangle=-45, |
21 | | - autosize=False, |
22 | | - width=600, |
23 | | - height=600, |
24 | | - margin=dict(l=50, r=50, b=100, t=100, pad=4) |
25 | | -) |
26 | | -fig.show() |
| 28 | + try: |
| 29 | + create_line_chart(x_data, y_data) |
| 30 | + except Exception as e: |
| 31 | + print("An error occurred:", str(e)) |
0 commit comments