Plotting pandas DataFrames

View, run, and experiment with Plotting pandas DataFrames in CodeUtility's online Matplotlib IDE.

🚀 565,268 total executions (11,973 this month)
Embed
Output

Practice Python with coding challenges

Solve hands-on problems right in this editor: run the sample tests, submit, and get an AI code review.

All Python challenges
Easy

Rectangle Perimeter

Compute the perimeter of a rectangle from its sides.

You'll learn ArithmeticReturn values
BeginnerLearning-pathVariables
Easy

Days in a Month

Return how many days a month has, including leap years.

You'll learn Calendar rulesHelper functions
BeginnerConditionsFunctionsLearning-path
Easy

Dot Product of Two Vectors

Multiply two vectors element by element and add the results: the core operation of every neuron.

You'll learn VectorsDot product
Neural networksaimachine learning
Easy

Distance Between Points

Compute the straight-line distance between two points.

You'll learn Pythagorean theoremSquare roots
BeginnerFunctionsLearning-pathmath
Easy

Average of Three

Average three whole numbers.

You'll learn ArithmeticDivision
BeginnerLearning-pathVariables
Easy

To-Do List

Keep a list of tasks: add them, mark them done, remove them and report what is still pending.

You'll learn Typed collectionsRecords
BeginnerSimulationStrings
Easy

Prime Number Check

Decide whether a number is prime.

You'll learn DivisibilityLoop optimization
BeginnerLoopsNumbersStudent-beginner
Hard

Word Break

Decide whether text can be split into dictionary words.

You'll learn Prefix DPString segmentation
AdvancedDynamic-programmingHackathonStrings
Easy

Count Pairs With a Sum

Count pairs of positions whose values add up to a target.

You'll learn Pairs of indexesAvoiding double counts
ArraysBeginnerLearning-pathNested-loops
Easy

Missing Number

Find the one number missing from 0..n.

You'll learn Arithmetic seriesSum difference trick
ArraysBeginnerStudent-beginnermath
Medium

K-th Smallest Element

Find the k-th smallest value without fully sorting.

You'll learn QuickselectPartitioning
AdvancedCompetitive-programmingSorting
Easy

Min and Max Together

Find the smallest and largest value in one pass.

You'll learn Single passMultiple return values
ArraysBeginnerFunctionsLearning-path

📊 About This Matplotlib Online Executor

The CodeUtility Matplotlib Executor allows you to write and run Python code that includes Matplotlib plotting commands - directly in your browser, with no setup or local installation required. It runs real Python environments with Matplotlib preinstalled, enabling instant visual output generation.

This tool uses the latest Matplotlib version and supports typical Python libraries used in data analysis and scientific computing, including NumPy and Pandas.

You can create 2D charts, scatter plots, histograms, or custom visualizations - the tool automatically captures your figure and displays it in a popup window when the code runs successfully.

It’s perfect for learners, data scientists, and engineers who want to quickly experiment with Python visualization code without needing Jupyter Notebook or a local Python setup.

More than a code runner

Use a multi-file editor, an isolated execution terminal, runtime-specific libraries, persistent workspaces, sharing, and real-time collaboration from the same executor.

How to use this executor?

Choose a runtime, open or create a file, write your code, and select Run. Output appears in the terminal, while signed-in users can keep files in a workspace, install libraries, and collaborate through shares.

  1. Select a version and edit the current file or open another workspace file.
  2. Run the code, provide input in the terminal when requested, and review saved run history.
  3. Use libraries, workspace tools, sharing, and chat when your task needs more than one snippet.

📊 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()