For beginners or users who need to quickly validate visualization code, setting up a local Python environment can be a significant barrier. This guide shows how to use the Online Python Runner (based on Python 3.12.7) to execute Matplotlib code directly in your browser and view or download the generated plots—without installing any software.
Tool Features
- Python 3.12.7 with full standard library support
- Built-in support for common data science libraries (e.g., NumPy, Pandas, Matplotlib) via package manager
- Virtual file system for creating, previewing, and downloading files (including
.png
,.jpg
,.svg
, etc.) - Instant code execution with real-time output
- Ideal for teaching, code validation, and lightweight data visualization
Try it here: https://toolshu.com/python3
How to Use
1. Write Plotting Code
Enter the following example in the editor:
import matplotlib.pyplot as plt
# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 25, 30]
# Plot
plt.figure(figsize=(6, 4))
plt.plot(x, y, marker='o')
plt.title('Simple Line Plot')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
plt.savefig('output.png')
print("Image saved as output.png")
2. Run the Code
Click Run. The console will confirm that the image has been saved.
3. View and Download the Image
- Open the File Browser in the interface
- Locate
output.png
- Click Preview to view the image online, or Download to save it locally
Important Notes
- The virtual file system is session-scoped. Files may be lost when you close the browser tab—download important outputs promptly.
- While common libraries are supported, packages requiring C extensions or system-level dependencies may not work.
- This environment is optimized for small- to medium-sized scripts and educational use, not for long-running or resource-intensive tasks.
Common Plotting Examples
1. Basic Line Plot
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 5, 3, 8, 7]
plt.plot(x, y, marker='o')
plt.title('Line Plot')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
plt.savefig('line_plot.png')
plt.close()
2. Bar Chart
import matplotlib.pyplot as plt
categories = ['A', 'B', 'C', 'D']
values = [23, 45, 56, 78]
plt.bar(categories, values, color='skyblue')
plt.title('Bar Chart')
plt.xlabel('Category')
plt.ylabel('Value')
plt.show()
plt.savefig('bar_chart.png')
plt.close()
3. Scatter Plot
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
x = np.random.randn(100)
y = 2 * x + np.random.randn(100)
plt.scatter(x, y, alpha=0.7)
plt.title('Scatter Plot')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
plt.savefig('scatter_plot.png')
plt.close()
4. Multiple Subplots
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
fig, axs = plt.subplots(2, 1, figsize=(6, 6))
axs[0].plot(x, y1)
axs[0].set_title('sin(x)')
axs[1].plot(x, y2, color='orange')
axs[1].set_title('cos(x)')
plt.tight_layout()
plt.show()
plt.savefig('subplots.png')
plt.close()
5. Integration with Pandas
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({
'Month': ['Jan', 'Feb', 'Mar', 'Apr'],
'Sales': [200, 250, 300, 280]
})
df.plot(x='Month', y='Sales', kind='bar', color='green')
plt.title('Monthly Sales')
plt.show()
plt.savefig('pandas_bar.png')
plt.close()
6. High-Resolution Output
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)
plt.figure(figsize=(8, 4))
plt.plot(x, y)
plt.title('High-Resolution Sine Wave')
plt.show()
plt.savefig('sine_hd.png', dpi=300, bbox_inches='tight')
plt.close()
Tip: Always call
plt.close()
(orplt.clf()
) at the end of your script to prevent plot state from leaking between runs.
Summary
This online Python environment significantly lowers the barrier to entry for data visualization in Python. It’s especially valuable for teaching, rapid prototyping, and ad-hoc plotting—letting you focus on code logic rather than environment setup.
Get started now: https://toolshu.com/python3
Article URL:https://toolshu.com/en/article/rq6ksnak
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 。
Loading...