How to do a scatter plot with empty circles in Python?

scatter plot python
matplotlib plot empty circle
add circle to scatter plot python
matplotlib marker fill none
plt.plot empty circle
matplotlib plot circle no fill
matplotlib circle
how to generate a random color for a matplotlib plot?

In Python, with Matplotlib, how can a scatter plot with empty circles be plotted? The goal is to draw empty circles around some of the colored disks already plotted by scatter(), so as to highlight them, ideally without having to redraw the colored circles.

I tried facecolors=None, to no avail.

From the documentation for scatter:

Optional kwargs control the Collection properties; in particular:

    edgecolors:
        The string ‘none’ to plot faces with no outlines
    facecolors:
        The string ‘none’ to plot unfilled outlines

Try the following:

import matplotlib.pyplot as plt 
import numpy as np 

x = np.random.randn(60) 
y = np.random.randn(60)

plt.scatter(x, y, s=80, facecolors='none', edgecolors='r')
plt.show()

Note: For other types of plots see this post on the use of markeredgecolor and markerfacecolor.

How to do a scatter plot with empty circles in Python?, Matplotlib Scatter Exercises, Practice and Solution: Write a Python program to draw a scatter plot with empty circles taking a random distribution� You can use Prelude’s command to do a second scatter plot of the hightlighted points with an empty circle and a first call to plot all the points. Make sure the s paramter is sufficiently small for the larger empty circles to enclose the smaller filled ones.

Would these work?

plt.scatter(np.random.randn(100), np.random.randn(100), facecolors='none')

or using plot()

plt.plot(np.random.randn(100), np.random.randn(100), 'o', mfc='none')

Matplotlib Scatter: Draw a scatter plot with empty circles taking a , Question. In Python, with Matplotlib, how can a scatter plot with empty circles be plotted? The goal is to draw empty circles around some of the colored disks� Matplotlib Scatter: Exercise-2 with Solution. Write a Python program to draw a scatter plot with empty circles taking a random distribution in X and Y and plotted against each other.

Here's another way: this adds a circle to the current axes, plot or image or whatever :

from matplotlib.patches import Circle  # $matplotlib/patches.py

def circle( xy, radius, color="lightsteelblue", facecolor="none", alpha=1, ax=None ):
    """ add a circle to ax= or current axes
    """
        # from .../pylab_examples/ellipse_demo.py
    e = Circle( xy=xy, radius=radius )
    if ax is None:
        ax = pl.gca()  # ax = subplot( 1,1,1 )
    ax.add_artist(e)
    e.set_clip_box(ax.bbox)
    e.set_edgecolor( color )
    e.set_facecolor( facecolor )  # "none" not None
    e.set_alpha( alpha )

(The circles in the picture get squashed to ellipses because imshow aspect="auto" ).

How to do a scatter plot with empty circles in Python?, In Python, with Matplotlib, how can a scatter plot with empty circles be plotted? The goal is to draw empty circles around some of the colored disks already� How to do a scatter plot with empty circles in Python? In Python, with Matplotlib, how can a scatter plot with empty circles be plotted? The goal is to draw empty circles around some of the colored disks already plotted by scatter(), so as to highlight them, ideally without having to redraw the colored circles.

In matplotlib 2.0 there is a parameter called fillstyle which allows better control on the way markers are filled. In my case I have used it with errorbars but it works for markers in general http://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.errorbar.html

fillstyle accepts the following values: [‘full’ | ‘left’ | ‘right’ | ‘bottom’ | ‘top’ | ‘none’]

There are two important things to keep in mind when using fillstyle,

1) If mfc is set to any kind of value it will take priority, hence, if you did set fillstyle to 'none' it would not take effect. So avoid using mfc in conjuntion with fillstyle

2) You might want to control the marker edge width (using markeredgewidth or mew) because if the marker is relatively small and the edge width is thick, the markers will look like filled even though they are not.

Following is an example using errorbars:

myplot.errorbar(x=myXval, y=myYval, yerr=myYerrVal, fmt='o', fillstyle='none', ecolor='blue',  mec='blue')

How to do a scatter plot with empty circles in Python?, This question already has an answer here: How to do a scatter plot with empty circles in Python? 5 answers I'm trying to plot a scatter plot with pandas api where � In this Tutorial we will learn how to create Scatter plot in python with matplotlib. This python Scatter plot tutorial also includes the steps to create scatter plot by groups in which scatter plot is created for different groups. Create Scatter plot in Python: This example we will create scatter plot for weight vs height

Basend on the example of Gary Kerr and as proposed here one may create empty circles related to specified values with following code:

import matplotlib.pyplot as plt 
import numpy as np 
from matplotlib.markers import MarkerStyle

x = np.random.randn(60) 
y = np.random.randn(60)
z = np.random.randn(60)

g=plt.scatter(x, y, s=80, c=z)
g.set_facecolor('none')
plt.colorbar()
plt.show()

Matplotlib: How to plot an empty circle in an scatter plot using , From the documentation for scatter: Optional kwargs control the Collection properties; in particular: edgecolors: The string 'none' to plot faces with no outlines� Write a Python program to draw a scatter plot with empty circles taking a random distribution in X and Y and plotted against each other. Go to the editor The code snippet gives the output shown in the following screenshot:

How to do a scatter plot with empty circles in Python?, The following also demonstrates how transparency of the markers can be adjusted by giving alpha a value between 0 and 1. import numpy as np np. random. In the following code below, we create a scatter plot. import matplotlib.pyplot as plt testscores_class1=[35, 50, 65, 82, 90, 99] timestudying= [1,3, 4,6, 7, 8] plt.scatter(timestudying, testscores_class1) plt.title('Student Test Grades') plt.xlabel('Time Spent Studying') plt.ylabel('Test Scores') plt.show()

Scatter plots with a legend — Matplotlib 3.1.0 documentation, Make multiple marker types If your control group is all circles and your experimental group scatterplot using a variety of markers. import matplotlib.pyplot as plt circle1 = plt.Circle((0, 0), 0.5, color='r') fig, ax = plt.subplots() plt.xlim(-1.25,1.25) plt.ylim(-1.25,1.25) plt.grid(linestyle='--') ax.set_aspect(1) ax.add_artist(circle1) plt.title('How to plot a circle with matplotlib ?', fontsize=8) plt.savefig("plot_circle_matplotlib_02.png", bbox_inches='tight') plt.show()

Markers in Matplotlib, In Python, with Matplotlib, how can a scatter plot with empty circles be plotted? The goal is to draw empty circles around some of the colored disks already� Matplot has a built-in function to create scatterplots called scatter(). A scatter plot is a type of plot that shows the data as a collection of points. The position of a point depends on its two-dimensional value, where each value is a position on either the horizontal or vertical dimension.

Comments
  • People looking to draw empty/hollow scatter plots with different colors may look at this question.
  • Thanks! The gotcha is that the more usual (in Python) facecolors=None does not work, which tripped me.
  • Very helpful. It's markerfacecolor='none', this is the way it's now.
  • I had my matplotlib style in a way that set the edges widths to zero. If you don't see any markers with markerfacecolor='none' try adding markeredgewidth=1.0
  • This approach can also be used in Seaborn after doing the standard import of Matplotlib %matplotlib inline and import matplotlib.pyplot as plt, and then setting Seaborn to be the plotting default by import seaborn as sns; sns.set()
  • this is useful for when you use plot instead of scatter
  • For scatter, you need to specify edgecolors like edgecolors='r'. Otherwise, the circles disappear. See here
  • This is the essentially a complexified version the accepted answer…
  • From my point is it not. Using scatter plot with colors does not except facecolor="none" within the command. Therefor the subsequent removement of the facecolor is needed as described in the given link. Unfortunaly this complexified solution is needed to remove the facecolor in scatter plots with colorcoding.
  • The approach in this answer is indeed useful if one wants to update a graph that originally does not contain empty circles. However, the question about creating these circles directly, so the accepted solution is the way to go, as it does the same as this answer but directly, with no extraneous update of a first graph.
  • This "complexified version" worked for me when embedding the argument within .scatter() did not. For context, I was also applying a colormap (c=z, cmap='jet').