.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_intro_matplotlib_auto_examples_exercises_plot_exercise_2.py: Exercise 2 =========== Exercise 2 with matplotlib. .. image:: /intro/matplotlib/auto_examples/exercises/images/sphx_glr_plot_exercise_2_001.png :class: sphx-glr-single-img .. code-block:: python import numpy as np import matplotlib.pyplot as plt # Create a new figure of size 8x6 points, using 100 dots per inch plt.figure(figsize=(8, 6), dpi=80) # Create a new subplot from a grid of 1x1 plt.subplot(111) X = np.linspace(-np.pi, np.pi, 256) C, S = np.cos(X), np.sin(X) # Plot cosine using blue color with a continuous line of width 1 (pixels) plt.plot(X, C, color="blue", linewidth=1.0, linestyle="-") # Plot sine using green color with a continuous line of width 1 (pixels) plt.plot(X, S, color="green", linewidth=1.0, linestyle="-") # Set x limits plt.xlim(-4., 4.) # Set x ticks plt.xticks(np.linspace(-4, 4, 9)) # Set y limits plt.ylim(-1.0, 1.0) # Set y ticks plt.yticks(np.linspace(-1, 1, 5)) # Show result on screen plt.show() **Total running time of the script:** ( 0 minutes 0.019 seconds) .. _sphx_glr_download_intro_matplotlib_auto_examples_exercises_plot_exercise_2.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_exercise_2.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_exercise_2.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_