Files
jupyter-collection/scientific-computing-2/auto_examples_jupyter_2/exercises/plot_exercise_2.ipynb
2025-10-21 11:20:44 +08:00

43 lines
1.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Exercise 2\n\nExercise 2 with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\n# Create a new figure of size 8x6 points, using 100 dots per inch\nplt.figure(figsize=(8, 6), dpi=80)\n\n# Create a new subplot from a grid of 1x1\nplt.subplot(111)\n\nX = np.linspace(-np.pi, np.pi, 256)\nC, S = np.cos(X), np.sin(X)\n\n# Plot cosine using blue color with a continuous line of width 1 (pixels)\nplt.plot(X, C, color=\"blue\", linewidth=1.0, linestyle=\"-\")\n\n# Plot sine using green color with a continuous line of width 1 (pixels)\nplt.plot(X, S, color=\"green\", linewidth=1.0, linestyle=\"-\")\n\n# Set x limits\nplt.xlim(-4.0, 4.0)\n\n# Set x ticks\nplt.xticks(np.linspace(-4, 4, 9))\n\n# Set y limits\nplt.ylim(-1.0, 1.0)\n\n# Set y ticks\nplt.yticks(np.linspace(-1, 1, 5))\n\n# Show result on screen\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}