Online Matplotlib Playground – Create Python Plots in Your Browser

Visualize data with Python and Matplotlib right in your browser using our online Matplotlib playground. Instantly render plots — no setup needed, perfect for data science.

🚀 7 total executions (7 this month)

✨ Popular Matplotlib courses people love

Loading...

📊 Introduction to Matplotlib

1. What is Matplotlib?

Matplotlib is a popular Python library used for creating static, animated, and interactive visualizations. It is especially useful in data science and scientific computing.

import matplotlib.pyplot as plt

2. Line Plot

A basic line chart using X and Y values.

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [2, 4, 6, 8]

plt.plot(x, y)
plt.title("Line Plot")
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.show()

3. Bar Chart

Bar charts are useful for comparing discrete categories.

categories = ['A', 'B', 'C']
values = [5, 7, 3]

plt.bar(categories, values)
plt.title("Bar Chart")
plt.show()

4. Scatter Plot

Use scatter plots to show relationships between two numeric variables.

x = [1, 2, 3, 4]
y = [10, 20, 25, 30]

plt.scatter(x, y)
plt.title("Scatter Plot")
plt.show()

5. Pie Chart

Pie charts are used to show proportions.

labels = ['Apple', 'Banana', 'Cherry']
sizes = [30, 40, 30]

plt.pie(sizes, labels=labels, autopct='%1.1f%%')
plt.title("Fruit Distribution")
plt.show()

6. Histogram

Histograms help understand the distribution of numerical data.

import numpy as np

data = np.random.randn(1000)

plt.hist(data, bins=30)
plt.title("Histogram")
plt.show()

7. Multiple Plots

Plot multiple charts in one figure using subplots.

x = [1, 2, 3, 4]
y1 = [1, 4, 9, 16]
y2 = [2, 3, 5, 7]

plt.subplot(1, 2, 1)
plt.plot(x, y1)
plt.title("Plot 1")

plt.subplot(1, 2, 2)
plt.plot(x, y2)
plt.title("Plot 2")

plt.tight_layout()
plt.show()

8. Customize Styles

You can customize colors, styles, markers, and more.

plt.plot(x, y1, color='red', linestyle='--', marker='o')
plt.title("Styled Line")
plt.show()

9. Save Plot as Image

Save your plot to an image file using savefig().

plt.plot(x, y1)
plt.savefig("my_plot.png")

10. 3D Plot (Advanced)

Matplotlib also supports 3D plotting via mpl_toolkits.mplot3d.

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

x = [1, 2, 3]
y = [2, 3, 4]
z = [5, 6, 7]

ax.scatter(x, y, z)
plt.show()