Reading-Notes

View the Project on GitHub MohammadAl-khatib/Reading-Notes

Data Visualization

This article discusses the role of matplotlib in data visualization using Python, it provides several useful methods for rendering graphs, some of which are:

  1. Plotting:

    • After importing matplotlib, you can use the method plot to generate figures, x-axis and y-axis values are provided usually as arrays.
  2. Changing colors and line widths:
    • Color and line width can be set as arguments to plot method, the following draws 2 lines with different colors

      plt.figure(figsize=(10,6), dpi=80)

      plt.plot(X, C, color=”blue”, linewidth=2.5, linestyle=”-“)

      plt.plot(X, S, color=”red”, linewidth=2.5, linestyle=”-“)

      plot

  3. Setting limits:
    • As you see the lines are touching the limits of the graph, you can scale the graph using:

      plt.xlim(X.min()1.1, X.max()1.1)

      plt.ylim(C.min()1.1, C.max()1.1)

      plot

  4. Setting ticks:
    • The values that appear on an axis are called ticks, those can be changed using:

      plt.xticks( [-np.pi, -np.pi/2, 0, np.pi/2, np.pi])

      plt.yticks([-1, 0, +1])

      plot

  5. Setting tick labels:
    • To change the tick lable use plt.xticks and plt.yticks:

      plot

  6. Moving spines:
    • Consider spines as the borders of the last graph, their position can be changed using .spines

      plot

Many other methods for modifying graphs can be found here