[[Python]] [[matplotlib]] >[!From Documentation] [`matplotlib.pyplot`](https://matplotlib.org/stable/api/pyplot_summary.html#module-matplotlib.pyplot "matplotlib.pyplot") is a state-based interface to matplotlib. It provides an implicit, MATLAB-like, way of plotting. It also opens figures on your screen, and acts as the figure GUI manager. ```python from matplotlib import pyplot as plt ``` ## show() you have to use this command to actually open a window and show the plot you created ## Visualizing a matrix Using a 100x100 np.array of numbers 0-9: ### matshow ```python plt.matshow(array) plt.show() ``` Output: ![[Screenshot 2023-02-12 at 2.06.52 PM.jpg|med]] ### imshow does the same thing? ```python plt.imshow(array) plt.show() ``` ![[Screenshot 2023-02-12 at 2.28.02 PM.jpg|med]] ## Figure objects ```python fig = plt.figure(num = 1, figsize = (4,4)) ``` - `num`: identified number (see "Figure 1") - `figsize`: `[width,height]` of the window in inches ## Pie charts ```python plt.pie(values) ``` Properties: `labels` = List of label text `autpct` = string formatting for percent labels `pctdistance`, `labeldistance` = distance of percent and label text from the center, proportional to the radius of the pie chart `startangle` = angle to start at, default 0º ## Bar charts ```python plt.bar(categories, values) ``` ## Legends ```python plt.legend(loc = "center right") ``` ## Titles ``` plt.title("Title") plt.xlabel("X Axis Label") plt.ylabel("Y Axis Title") ``` ## Get current figure and axis ```python plt.gca() plt.gcf() ```