How to create data charts using Python?

You can utilize various popular Python libraries to create data charts in Python, such as:

  1. Matplotlib is a powerful and flexible plotting library that can create various types of charts, including line plots, scatter plots, bar plots, pie charts, and more. Below is an example of creating a bar plot.
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [10, 15, 7, 12, 9]

plt.bar(x, y)
plt.xlabel('x轴标签')
plt.ylabel('y轴标签')
plt.title('柱状图')

plt.show()
  1. Seaborn: Seaborn is an advanced data visualization library built on top of Matplotlib, with a simpler interface and more aesthetically pleasing default styles. Here is an example of drawing a scatter plot:
import seaborn as sns

x = [1, 2, 3, 4, 5]
y = [10, 15, 7, 12, 9]

sns.scatterplot(x, y)
plt.xlabel('x轴标签')
plt.ylabel('y轴标签')
plt.title('散点图')

plt.show()
  1. Pandas: Pandas is a data processing library that includes some plotting capabilities. Below is an example of using Pandas to create a line graph.
import pandas as pd

data = {'x': [1, 2, 3, 4, 5], 'y': [10, 15, 7, 12, 9]}
df = pd.DataFrame(data)

df.plot(x='x', y='y', kind='line')
plt.xlabel('x轴标签')
plt.ylabel('y轴标签')
plt.title('折线图')

plt.show()

In addition to the libraries mentioned above, there are other libraries available for data visualization, such as Plotly, Bokeh, etc. Choose the appropriate library based on your needs and preferences to create data charts.

bannerAds