DEV Community

Cover image for Creating 2D and 3D Plots and Graphs Using Python and Embedding them into Excel or Website
Sona
Sona

Posted on

Creating 2D and 3D Plots and Graphs Using Python and Embedding them into Excel or Website

Python provides powerful libraries like Matplotlib and Plotly for creating various types of plots and graphs. In this tutorial, we will explore how to create 2D and 3D plots and graphs and integrate them into a website or export them to Excel.

  1. Creating a 2D Plot with Matplotlib:

Matplotlib is a versatile library for creating static, animated, and interactive visualizations in Python. Let’s create a simple 2D plot:

import matplotlib.pyplot as plt
import numpy as np

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

# Create plot
plt.figure(figsize=(8, 6))
plt.plot(x, y, label='sin(x)')
plt.xlabel('x')
plt.ylabel('sin(x)')
plt.title('2D Plot with Matplotlib')
plt.legend()
plt.grid(True)
plt.savefig('2d_plot.png')  # Save the plot as an image
plt.show()
Enter fullscreen mode Exit fullscreen mode

Read More

Top comments (0)