1

I want to plot a graph of 3D spheres that vary in size according to one data set of the format

(name, x-coord, y-coord, sphere_volume)

These need to be plotted on the graph based against values of x and y, but a fixed z-value is acceptable; it could be a 2D set of axes, just with 3D spheres varying in size instead of the usual circles you can get with a scatter graph. I also want each of these labelled; either with a name, or with a number than then corresponds to a name in a key.

Which matplotlib module should I use for this? I specifically only want to use matplotlib to output the graphics; though other modules can be used to manipulate the data. I was thinking of adapting the output from this:

import numpy as np
import matplotlib.pyplot as plt

N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2  # 0 to 15 point radii

plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.show()

enter image description here

so that the circles were instead spheres, but I'm not sure how to go about this; any tips? A nice bonus would be to be able to define the colour of the sphere, but this is less important.

Noah P
  • 111
  • 4
  • Have a look [here](https://stackoverflow.com/questions/24123659/scatter-plot-3d-with-labels-and-spheres) – Sheldore Oct 20 '18 at 17:55
  • I was hoping for actual spheres rather than just a wireframe; they don't look fantastic. – Noah P Oct 20 '18 at 17:58
  • Is [this](https://stackoverflow.com/questions/10958835/matplotlib-color-gradient-in-patches/10995481) what you're looking for? – ImportanceOfBeingErnest Oct 20 '18 at 18:21
  • Not quite @ImportanceOfBeingErnest; I was hoping for actual spheres rather than that, in a 3D plot. – Noah P Oct 20 '18 at 18:42
  • Oh, so you do want a 3D plot. Something like [this](https://stackoverflow.com/questions/45324258/draw-many-spheres-efficiently) (use the code in the question for matplotlib, the answer shows an alternative not using matplotlib). – ImportanceOfBeingErnest Oct 20 '18 at 19:13
  • @ImportanceOfBeingErnest This doesn't address the use of a key though? – Noah P Oct 22 '18 at 09:45
  • You mean https://stackoverflow.com/questions/10374930/matplotlib-annotating-a-3d-scatter-plot ? – ImportanceOfBeingErnest Oct 22 '18 at 10:37
  • @ImportanceOfBeingErnest Not quite; a key is a separate box off to the side. Each sphere will be labelled with a number, but these each correspond to a name; the key should display that info – Noah P Oct 22 '18 at 12:27
  • Seems that's a totally [different question](https://stackoverflow.com/questions/52914413/how-to-generate-a-key-in-matplotlib). – ImportanceOfBeingErnest Oct 22 '18 at 12:34
  • Because the question was closed - I'd have preferred it to be included with the original – Noah P Oct 22 '18 at 12:48

0 Answers0