Spaces:
Runtime error
Runtime error
File size: 2,028 Bytes
4858ba5 |
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import matplotlib.pyplot as plt
def plot_bar_chart(data):
fig, ax = plt.subplots()
labels = data['labels']
values = data['values']
for value in values:
ax.bar(labels, value['data'], label=value['label'])
ax.set_title('Bar Chart')
ax.set_xlabel('Labels')
ax.set_ylabel('Values')
ax.legend()
return fig
def plot_horizontal_bar_chart(data):
fig, ax = plt.subplots()
labels = data['labels']
values = data['values']
for value in values:
ax.barh(labels, value['data'], label=value['label'])
ax.set_title('Horizontal Bar Chart')
ax.set_xlabel('Values')
ax.set_ylabel('Labels')
ax.legend()
return fig
def plot_line_graph(data):
fig, ax = plt.subplots()
x_values = data['xValues']
y_values_list = data['yValues']
for y_values in y_values_list:
label = y_values.get('label', None)
ax.plot(x_values, y_values['data'], label=label)
ax.set_title('Line Graph')
ax.set_xlabel('X Values')
ax.set_ylabel('Y Values')
if any('label' in y_values for y_values in y_values_list):
ax.legend()
return fig
def plot_scatter(data):
fig, ax = plt.subplots()
for series in data['series']:
x_values = [point['x'] for point in series['data']]
y_values = [point['y'] for point in series['data']]
label = series.get('label', None)
ax.scatter(x_values, y_values, label=label)
ax.set_title('Scatter Plot')
ax.set_xlabel('X Values')
ax.set_ylabel('Y Values')
if any('label' in series for series in data['series']):
ax.legend()
return fig
def plot_pie(data):
values = [item['value'] for item in data]
labels = [item['label'] for item in data]
fig, ax = plt.subplots()
wedges, texts, autotexts = ax.pie(values, labels=labels, autopct='%1.1f%%', startangle=140)
ax.set_title('Pie Chart')
for text in texts + autotexts:
text.set_fontsize(10)
return fig |