\Dfrac 与 \Frac 的区别

PythonPythonBeginner
立即练习

This tutorial is from open-source community. Access the source code

💡 本教程由 AI 辅助翻译自英文原版。如需查看原文,您可以 切换至英文原版

简介

Matplotlib 是 Python 中的一个数据可视化库。在本教程中,我们将讨论在 Matplotlib 中使用 Mathtex 时 \dfrac 和 \frac TeX 宏之间的区别。

虚拟机使用提示

虚拟机启动完成后,点击左上角切换到“笔记本”标签页,以访问 Jupyter Notebook 进行练习。

有时,你可能需要等待几秒钟让 Jupyter Notebook 完成加载。由于 Jupyter Notebook 的限制,操作验证无法自动化。

如果你在学习过程中遇到问题,随时向 Labby 提问。课程结束后提供反馈,我们会及时为你解决问题。


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL matplotlib(("Matplotlib")) -.-> matplotlib/BasicConceptsGroup(["Basic Concepts"]) matplotlib(("Matplotlib")) -.-> matplotlib/PlottingDataGroup(["Plotting Data"]) python(("Python")) -.-> python/DataStructuresGroup(["Data Structures"]) matplotlib(("Matplotlib")) -.-> matplotlib/PlotCustomizationGroup(["Plot Customization"]) python(("Python")) -.-> python/DataScienceandMachineLearningGroup(["Data Science and Machine Learning"]) python(("Python")) -.-> python/ModulesandPackagesGroup(["Modules and Packages"]) matplotlib/BasicConceptsGroup -.-> matplotlib/importing_matplotlib("Importing Matplotlib") matplotlib/BasicConceptsGroup -.-> matplotlib/figures_axes("Understanding Figures and Axes") matplotlib/PlottingDataGroup -.-> matplotlib/line_plots("Line Plots") python/DataStructuresGroup -.-> python/tuples("Tuples") python/DataStructuresGroup -.-> python/sets("Sets") matplotlib/PlotCustomizationGroup -.-> matplotlib/legend_config("Legend Configuration") python/ModulesandPackagesGroup -.-> python/importing_modules("Importing Modules") python/DataScienceandMachineLearningGroup -.-> python/numerical_computing("Numerical Computing") python/DataScienceandMachineLearningGroup -.-> python/data_visualization("Data Visualization") subgraph Lab Skills matplotlib/importing_matplotlib -.-> lab-48690{{"\Dfrac 与 \Frac 的区别"}} matplotlib/figures_axes -.-> lab-48690{{"\Dfrac 与 \Frac 的区别"}} matplotlib/line_plots -.-> lab-48690{{"\Dfrac 与 \Frac 的区别"}} python/tuples -.-> lab-48690{{"\Dfrac 与 \Frac 的区别"}} python/sets -.-> lab-48690{{"\Dfrac 与 \Frac 的区别"}} matplotlib/legend_config -.-> lab-48690{{"\Dfrac 与 \Frac 的区别"}} python/importing_modules -.-> lab-48690{{"\Dfrac 与 \Frac 的区别"}} python/numerical_computing -.-> lab-48690{{"\Dfrac 与 \Frac 的区别"}} python/data_visualization -.-> lab-48690{{"\Dfrac 与 \Frac 的区别"}} end

导入 Matplotlib

要使用 Matplotlib,我们首先需要导入它。我们还将导入 numpy 以生成一些用于可视化的示例数据。

import matplotlib.pyplot as plt
import numpy as np

创建示例数据

我们将创建两个用于绘图的示例数据数组。

x = np.linspace(0, 10, 100)
y = np.sin(x)

创建图形和坐标轴

我们将创建一个图形和坐标轴对象,以便在上面绘制数据。

fig, ax = plt.subplots()

使用 \frac 绘制数据

我们将使用 \frac TeX 宏来绘制数据,并显示生成的图形。

ax.plot(x, y, label=r'$\frac{sin(x)}{x}$')
ax.legend()
plt.show()

使用 \dfrac 绘制数据

我们将使用 \dfrac TeX 宏来绘制数据,并显示生成的图形。

fig, ax = plt.subplots()
ax.plot(x, y, label=r'$\dfrac{sin(x)}{x}$')
ax.legend()
plt.show()

总结

在本教程中,我们讨论了在 Matplotlib 中使用 Mathtex 时,\dfrac 和\frac TeX 宏之间的区别。我们展示了如何使用这两个宏来绘制数据并显示生成的图形。默认情况下,\frac 生成一个较小的行内样式分数,而\dfrac 生成一个较大的显示样式分数。