Differences Between \Dfrac and \Frac

PythonPythonBeginner
Practice Now

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

Introduction

Matplotlib is a data visualization library in Python. In this tutorial, we will discuss the differences between \dfrac and \frac TeX macros when using Mathtex in Matplotlib.

VM Tips

After the VM startup is done, click the top left corner to switch to the Notebook tab to access Jupyter Notebook for practice.

Sometimes, you may need to wait a few seconds for Jupyter Notebook to finish loading. The validation of operations cannot be automated because of limitations in Jupyter Notebook.

If you face issues during learning, feel free to ask Labby. Provide feedback after the session, and we will promptly resolve the problem for you.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL matplotlib(("`Matplotlib`")) -.-> matplotlib/BasicConceptsGroup(["`Basic Concepts`"]) matplotlib(("`Matplotlib`")) -.-> matplotlib/PlottingDataGroup(["`Plotting Data`"]) matplotlib(("`Matplotlib`")) -.-> matplotlib/PlotCustomizationGroup(["`Plot Customization`"]) python(("`Python`")) -.-> python/DataStructuresGroup(["`Data Structures`"]) python(("`Python`")) -.-> python/ModulesandPackagesGroup(["`Modules and Packages`"]) python(("`Python`")) -.-> python/DataScienceandMachineLearningGroup(["`Data Science and Machine Learning`"]) matplotlib/BasicConceptsGroup -.-> matplotlib/importing_matplotlib("`Importing Matplotlib`") matplotlib/BasicConceptsGroup -.-> matplotlib/figures_axes("`Understanding Figures and Axes`") matplotlib/PlottingDataGroup -.-> matplotlib/line_plots("`Line Plots`") matplotlib/PlotCustomizationGroup -.-> matplotlib/legend_config("`Legend Configuration`") python/DataStructuresGroup -.-> python/tuples("`Tuples`") python/DataStructuresGroup -.-> python/sets("`Sets`") 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{{"`Differences Between \Dfrac and \Frac`"}} matplotlib/figures_axes -.-> lab-48690{{"`Differences Between \Dfrac and \Frac`"}} matplotlib/line_plots -.-> lab-48690{{"`Differences Between \Dfrac and \Frac`"}} matplotlib/legend_config -.-> lab-48690{{"`Differences Between \Dfrac and \Frac`"}} python/tuples -.-> lab-48690{{"`Differences Between \Dfrac and \Frac`"}} python/sets -.-> lab-48690{{"`Differences Between \Dfrac and \Frac`"}} python/importing_modules -.-> lab-48690{{"`Differences Between \Dfrac and \Frac`"}} python/numerical_computing -.-> lab-48690{{"`Differences Between \Dfrac and \Frac`"}} python/data_visualization -.-> lab-48690{{"`Differences Between \Dfrac and \Frac`"}} end

Import Matplotlib

To use Matplotlib, we first need to import it. We will also import numpy to generate some sample data for visualization.

import matplotlib.pyplot as plt
import numpy as np

Create Sample Data

We will create two arrays of sample data to plot.

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

Create a Figure and Axis

We will create a figure and axis object to plot our data on.

fig, ax = plt.subplots()

Plot the Data with \frac

We will plot the data with the \frac TeX macro and display the resulting plot.

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

Plot the Data with \dfrac

We will plot the data with the \dfrac TeX macro and display the resulting plot.

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

Summary

In this tutorial, we discussed the differences between \dfrac and \frac TeX macros when using Mathtex in Matplotlib. We demonstrated how to plot data with both macros and display the resulting plots. By default, \frac produces a smaller, in-line style fraction, while \dfrac produces a larger, display style fraction.

Other Python Tutorials you may like