matplotlib scatter plot colour as function of third variable [duplicate]

This works for me, using matplotlib 1.1: import numpy as np import matplotlib.pyplot as plt x = np.arange(10) y = np.sin(x) plt.scatter(x, y, marker=”+”, s=150, linewidths=4, c=y, cmap=plt.cm.coolwarm) plt.show() Result: Alternatively, for n points, make an array of RGB color values with shape (n, 3), and assign it to the edgecolors keyword argument of scatter(): … Read more

Creating Pandas Dataframe between two Numpy arrays, then draw scatter plot

There are a number of ways to create DataFrames. Given 1-dimensional column vectors, you can create a DataFrame by passing it a dict whose keys are column names and whose values are the 1-dimensional column vectors: import numpy as np import pandas as pd x = np.random.randn(5) y = np.sin(x) df = pd.DataFrame({‘x’:x, ‘y’:y}) df.plot(‘x’, … Read more

Matplotlib scatterplot; color as a function of a third variable

There’s no need to manually set the colors. Instead, specify a grayscale colormap… import numpy as np import matplotlib.pyplot as plt # Generate data… x = np.random.random(10) y = np.random.random(10) # Plot… plt.scatter(x, y, c=y, s=500) plt.gray() plt.show() Or, if you’d prefer a wider range of colormaps, you can also specify the cmap kwarg to … Read more

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

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: … Read more