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