How to make a 3D scatter plot in matplotlib

You can use matplotlib for this. matplotlib has a mplot3d module that will do exactly what you want. import matplotlib.pyplot as plt import random fig = plt.figure(figsize=(12, 12)) ax = fig.add_subplot(projection=’3d’) sequence_containing_x_vals = list(range(0, 100)) sequence_containing_y_vals = list(range(0, 100)) sequence_containing_z_vals = list(range(0, 100)) random.shuffle(sequence_containing_x_vals) random.shuffle(sequence_containing_y_vals) random.shuffle(sequence_containing_z_vals) ax.scatter(sequence_containing_x_vals, sequence_containing_y_vals, sequence_containing_z_vals) plt.show() The code above generates a … Read more

Transparency for Poly3DCollection plot in matplotlib

I made a slight modification to the OP code and got the transparency working. It appears that the facecolors argument of Poly3DCollection overrides the transparency argument, so the solution was to set the color in a separate call to either Poly3DCollection.set_color or Poly3DCollection.set_facecolor: from matplotlib import pyplot as plt from mpl_toolkits.mplot3d.art3d import Poly3DCollection fig = … Read more

Scatterplot with different size, marker, and color from pandas dataframe

scatter can only do one kind of marker at a time, so you have to plot the different types separately. Fortunately pandas makes this easy: import matplotlib.pyplot as plt import pandas as pd x = {‘speed’: [10, 15, 20, 18, 19], ‘meters’ : [122, 150, 190, 230, 300], ‘type’: [‘phone’, ‘phone’, ‘gps’, ‘gps’, ‘car’], ‘weight’: … Read more

Scatterplot with too many points

One way to deal with this is with alpha blending, which makes each point slightly transparent. So regions appear darker that have more point plotted on them. This is easy to do in ggplot2: df <- data.frame(x = rnorm(5000),y=rnorm(5000)) ggplot(df,aes(x=x,y=y)) + geom_point(alpha = 0.3) Another convenient way to deal with this is (and probably more … Read more

Scatterplot with marginal histograms in ggplot2

This is not a completely responsive answer but it is very simple. It illustrates an alternate method to display marginal densities and also how to use alpha levels for graphical output that supports transparency: scatter <- qplot(x,y, data=xy) + scale_x_continuous(limits=c(min(x),max(x))) + scale_y_continuous(limits=c(min(y),max(y))) + geom_rug(col=rgb(.5,0,0,alpha=.2)) scatter