想学习用 Python 绘图吗?ChatGPT 将为您提供帮助。

该项目要求 ChatGPT 教您如何生成用于创建绘图和可视化的 Python 代码。只需简要描述您要创建的绘图,ChatGPT 就会使用流行的 Matplotlib 库生成必要的代码。该工具甚至允许没有编程经验的用户为他们的数据开发专业级的绘图。无论您是研究人员、数据科学家还是学生,ChatGPT 都可以让您在 Python 中轻松创建美观且信息丰富的图表。(由 ChatGPT 生成,稍有改动)。

方便的是,我们可以提出后续问题;在这里我们要求“绘制”
结果:要使用 Matplotlib 绘制 Iris 数据集,您可以使用以下代码:
# --> Trying of the suggestions from ChatGPT
# --> we removed the redundant lines (e.g. loading libraries and importing data) from the suggestion
# Create a figure and an axes
fig, ax = plt.subplots()
# Plot the data, coloring the points by the target values
scatter = ax.scatter(df['sepal length (cm)'], df['sepal width (cm)'], c=df['target'])
# Add a legend
legend = ax.legend(*scatter.legend_elements(), title='Species')
# Add a title
ax.set_title('Iris dataset')
# Show the plot
plt.show()

我们选择并要求绘制数据集中的特定列。例如,询问“显示‘萼片长度 (cm)’列的分布”
结果:
要显示 Pandas DataFrame 中列的分布,可以使用 DataFrame 的 hist() 函数。例如,要显示 Iris 数据集中 'sepal length (cm)' 列的分布,可以使用以下代码:
# Create a figure and an axes
fig, ax = plt.subplots()
# Plot the distribution of the 'sepal length (cm)' column
df['sepal length (cm)'].hist(ax=ax)
# Add a title
ax.set_title('Distribution of sepal length')
# Show the plot
plt.show()

您可能会注意到,绘图没有标签。因此,我们可以要求“用适当的轴标签重做”。
结果:
# Create a figure and an axes
fig, ax = plt.subplots()
# Plot the distribution of the 'sepal length (cm)' column
df['sepal length (cm)'].hist(ax=ax)
# Add axis labels
ax.set_xlabel('Sepal length (cm)')
ax.set_ylabel('Frequency')
# Add a title
ax.set_title('Distribution of sepal length')
# Show the plot
plt.show()

显示分布的另一个有用图是使用箱线图,它使我们能够可视化标准偏差并识别异常值。在这里,我们通过询问“show me boxplot of distributions of all columns in same plot”来获取单个图中显示的所有列的箱线图。
结果:要将 Pandas DataFrame 中所有列的分布显示为同一图上的箱线图,您可以使用 DataFrame 的 boxplot() 函数。例如,要将 Iris 数据集中所有列的分布显示为箱线图,您可以使用以下代码:
import matplotlib.pyplot as plt
import pandas as pd
from sklearn import datasets
# Load the Iris dataset
iris = datasets.load_iris()
# Create a DataFrame with the features
df = pd.DataFrame(iris.data, columns=iris.feature_names)
# Add a column with the target values
df['target'] = iris.target
# Create a figure and an axes
fig, ax = plt.subplots()
# Plot the boxplots of all columns
df.boxplot(ax=ax)
# Add a title
ax.set_title('Distributions of all columns')
# Show the plot
plt.show()

ChatGPT 是处理项目的绝佳工具。以解决您的问题的方式来构建问题很重要。请记住,将您的项目分成更小的块并分别处理它们是处理项目的关键。
要从 ChatGPT 询问编程问题,您只需提供对您的问题的清晰简洁的描述,以及任何相关代码或错误消息。您还应该指定您正在使用的编程语言和任何库或框架。
那么,让我们问问 ChatGPT 它是怎么想的。
在为 ChatGPT 制定提示时,请务必牢记以下几点,以便充分利用模型:
具体并清楚地说明您希望模型做什么。例如,与其问“你对这个话题了解多少?”,不如问“你能简要介绍一下这个话题的历史吗?”
如有必要,提供上下文。如果您要问有关特定事件或人的问题,请提供一些背景信息,以便模型可以理解您提出问题的背景。
简明扼要。长而复杂的提示可能难以让模型理解,并可能导致不太准确或相关的响应。
避免使用模型可能不熟悉的过于技术性的语言或行话。
避免在一个提示中问多个问题,最好一次问一个问题。
以下是 ChatGPT 的一些很好的提示示例:“你能解释一下监督学习和非监督学习的主要区别吗?” “神经网络的主要组成部分是什么,它们是如何工作的?” “请写一个关于可以读心的机器人的短篇小说”