Adding legend based on existing color series

You can create the legend handles using an empty plot with the color based on the colormap and normalization of the scatter plot. import pandas as pd import numpy as np; np.random.seed(1) import matplotlib.pyplot as plt x = [np.random.normal(5,2, size=20), np.random.normal(10,1, size=20), np.random.normal(5,1, size=20), np.random.normal(10,1, size=20)] y = [np.random.normal(5,1, size=20), np.random.normal(5,1, size=20), np.random.normal(10,2, size=20), np.random.normal(10,2, … Read more

color of a 3D surface plot in python

To get the correct colors, use the Z values to pick values from the color map: my_col = cm.jet(Z/np.amax(Z)) The result: using otherwise the same code as @Moritz. from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from matplotlib.ticker import LinearLocator, FormatStrFormatter import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111, … Read more

How to drag two 3D axes at once

In order to synchronize the rotation between two subplots in mplot3d you can connect the motion_notify_event to a function that reads the angles from rotated plot and applies it to the respective other plot. Here is an example from the gallery with the described functionality added. from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm import … Read more

Matplotlib plot zooming with scroll wheel

This should work. It re-centers the graph on the location of the pointer when you scroll. import matplotlib.pyplot as plt def zoom_factory(ax,base_scale = 2.): def zoom_fun(event): # get the current x and y limits cur_xlim = ax.get_xlim() cur_ylim = ax.get_ylim() cur_xrange = (cur_xlim[1] – cur_xlim[0])*.5 cur_yrange = (cur_ylim[1] – cur_ylim[0])*.5 xdata = event.xdata # get … Read more