

#Draw scatter plot matplotlib how to#
So far, you have seen how to capture the dataset in Python using lists (step 3 above).Īlternatively, you may capture the data using Pandas DataFrame. Optionally: Create the Scatter Diagram using Pandas DataFrame Those types of diagrams can help you determine if there is a linear relationship between the variables. Scatter diagrams are especially useful when applying linear regression models. This means that when the Unemployment Rate increases, the Stock Index Price decreases. You may notice that a negative relationship exists between the Unemployment_Rate and the Stock_Index_Price. plt.scatter (cmap’Set2) Read: Matplotlib invert y axis. We pass c parameter to set the variable represented by color and cmap parameter to set the colormap. To create a scatter plot, we use scatter () method. Run the code in Python, and you’ll get this scatter diagram: To define x-axis and y-axis data coordinates, we use linespace () and sin () function. Plt.ylabel('Stock Index Price', fontsize=14) Plt.xlabel('Unemployment Rate', fontsize=14) Plt.title('Unemployment Rate Vs Stock Index Price', fontsize=14) Plt.scatter(Unemployment_Rate, Stock_Index_Price, color='green')

Putting everything together, here is the complete Python code to create the scatter diagram for our example: import matplotlib.pyplot as plt
#Draw scatter plot matplotlib install#
You may check this guide for the steps to install a module in Python using pip. If you haven’t already done so, install the matplotlib module using the following command (under Windows): pip install matplotlib Steps to Create a Scatter Diagram in Python using Matplotlib Step 1: Install the Matplotlib module In the next section, you’ll see the steps to create a scatter diagram using a practical example.

The following template can be used in order to create a scatter diagram in Python using Matplotlib: import matplotlib.pyplot as plt
