Scatter plot in matplotlib

Create a scatter plot in matplotlib based on your data. You can add plot several series of scatters in one figure. For each serie, you can select color, size and transparency (alpha). Please provide label for scatters to create legend. You can also produce scatter plot with colors assigned to selected categorical column. In this case, only first scatter is displayed.

Please check Advanced options to change plot style, set title, axis labels and control legend position.


Required packages

You need below packages to use the code generated by recipe. All packages are automatically installed in MLJAR Studio.


Interactive recipe

You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.

In the below recipe, we assume that you have following variables available in your notebook:

  • X (type DataFrame)

Python code

# Python code will be here

Code explanation

  1. Please select DataFrame.
  2. Please select columns for x and y axis. You can set colot, size and transparency for each scatter. There can be several scatters in the plot.
  3. You can color points in the scatter based on categorical column from your DataFrame. Please check all options on Color widget. In the case of coloring by value, only one scatter (the first one) can be displayed in the figure.
  4. Please check Advanced options.
  5. You can set title and axis labels there.
  6. If you wouldlike to control position of legend in your plot, you can do this in Advanced options. The default value is best, which means that matplotlib will search for position that do not overlay chart points.
  7. You can apply different style for scatter figure.

matplotlib cookbook

Code recipes from matplotlib cookbook.