
Import matplotlib.pyplot as plt plt.rcdefaults()
#PYTHON INSTALL MATPLOTLIB CODE#
We can create appealing bar charts with Matplotlib with simple code snippet: This makes the metadata on the graph very easy to read. Modified the color for the curves to make the comparison easierĪdded a legend frame which introduces which colour represents what. If you notice, we actually did two things in this figure: Plt.legend(loc='upper left', frameon=False) Plt.plot(X, sin, color='red', label="sine") Plt.plot(X, cos, color='blue', label="cosine")

To add, we used numpy to create a non-linear curve! Changing color and Adding Legends in Matplotlib PlotĪs we saw, curves look nice but aren’t they all look so, similar? What if we want to change their color and show what each color represents? Let’s try drawing the sine and cosine curves together: So, it was just a matter of calling plot multiple times. X = np.linspace(-np.pi, np.pi, 256, endpoint=True) We use hist() function to make a Histogram. More the values in a range, higher the bar for a range. While graphs inform us how our data vary, histogram describes how our data is distributed. In this section, we introduce you to Histograms. When we run this code, we can see the following figure appear: What if we only want to see the actual points on the plot? Scatter plot achieves this: Note that we can also provide a title to this figure and labels to our Axes by using this snippet:Ībove plot was very much indicative of the points which were actually not passed in the array as it showed a line. It is important to call it otherwise, the plot won’t be shown on the screen. Plt.Note the last line with the show() function. Plt.ylabel("Usage of mobile phones in $'s".format(value_increment)) Plt.subplots_adjust(left=0.2, bottom=0.2) # Adjust layout to make room for the table: The_table = plt.table(cellText=cell_text, # Reverse colors and text labels to display the last value at the top. Plt.bar(index, data, bar_width, bottom=y_offset, color=colors)Ĭell_text.append() # Plot bars and create text labels for the table # Initialize the vertical-offset for the stacked bar chart. Rows = ("Make Calls", "Take Photos", "Texting", "Internet", "Playing games")Ĭolors = plt.cm.BuPu(np.linspace(0, 0.5, len(rows))) Moreover, you can also change the font family of the table. The table consists of 2d grid that can be index by using rows and columns. This table object can be grabbed to change the specific values within the table. The () method returns the table created passing the required data as parameters. **kwargs: Used to control table properties.edges (optional): This parameter is the cell edges to be drawn with a line.bbox (optional): This parameter is the bounding box to draw the table into.Loc (optional): This parameter is the position of the cell with respect to ax.colLoc (optional): The text alignment of the column header cells.(default: ‘left’).colColours (optional): The colors of the column header cells.colLabels (optional): The text of the column header cells.rowLoc (optional): The text alignment of the row header cells.rowColours (optional): The colors of the row header cells.rowLabels (optional): The text of the row header cells.colWidths (optional): The column widths in units of the axes.

cellLoc: The alignment of the text within the cells.cellColours: The background colors of the cells.cellText: The texts to place into the table cells.**kwargs are optional parameters to adjust for the size of the 2-d list passed as a parameter. rowLabels, rowColours, rowLoc, and colLabels, colColours, colLoc respectively are optional parameters for the function. The table can optionally have row and column headers. Any other dimensional data will not be accepted by the function. These parameters must be 2D lists, in which the outer lists define the rows and the inner list define the column values of each row. Specifying one of cellText or cellColours as a parameter to the matplotlib table function is mandatory.

Syntax of Matplotlib Table: (cellText=None, cellColours=None, cellLoc='right', colWidths=None, rowLabels=None, rowColours=None, rowLoc='left', colLabels=None, colColours=None, colLoc='center', loc='bottom', bbox=None, edges='closed', **kwargs)
#PYTHON INSTALL MATPLOTLIB FULL#

