C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Python matplotlib: How to assign a different opacity to each point in a scatter plot?

By : Venkie
Date : November 21 2020, 07:35 AM
hope this fix your issue I have a series of points I want to put on a scatter plot. Each point is weighted by how much I care about it. I want the dot on the scatter plot to have an opacity set according to how much I care about it. , tcaswell is correct. I simply need to add .tolist()
code :
``````colors = weights.apply(lambda x: (0,0,1,x)).tolist()
``````

Share :

## How can I control the color and opacity of each point in a python scatter plot?

By : user3841058
Date : March 29 2020, 07:55 AM
To fix the issue you can do I'm looking to graph a 4D data set (X, Y, Z, intensity) using opacity to represent intensity. I also want the color to be dependent on the Z variable as well to better show depth. , I would do something like the following:
code :
``````import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# choose your colormap
cmap = plt.cm.jet

# get a Nx4 array of RGBA corresponding to zs
# cmap expects values between 0 and 1
z_list = np.array(z_list) # if z_list is type `list`
colors = cmap(z_list / z_list.max())

# set the alpha values according to i_list
# must satisfy 0 <= i <= 1
i_list = np.array(i_list)
colors[:,-1] = i_list / i_list.max()

# then plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x_list, y_list, z_list, c=colors)
plt.show()
``````

## NVD3 Scatter Plot Point Opacity

By : Dejan Ostojic
Date : March 29 2020, 07:55 AM
Does that help I been trying to set the opacity of the points of a scatter plot generate by nvd3. I tried to use CSS to set the opacity of the points but it didn't work. Any idea on how to set the opacity? , You can override the nv.d3.css to achieve this
code :
``````.nvd3.nv-scatter.nv-single-point .nv-groups .nv-point {
fill-opacity: 0.8 !important;
stroke-opacity: 0.8 !important;
}
``````

## Python, Matplotlib, Scatter plot, Change color on the clicked point

By : Aaron Thomas
Date : March 29 2020, 07:55 AM
With these it helps I have a simple scatter plot with a picker event.
code :
``````import sys
import numpy as np
import matplotlib.pyplot as plt

testData = np.array([[0,0], [0.1, 0], [0, 0.3], [-0.4, 0], [0, -0.5]])
fig, ax = plt.subplots()
coll = ax.scatter(testData[:,0], testData[:,1], color=["blue"]*len(testData), picker = 5, s=[50]*len(testData))
plt.grid(True)
plt.axis([-0.5, 0.5, -0.5, 0.5])

def on_pick(event):
print testData[event.ind], "clicked"
coll._facecolors[event.ind,:] = (1, 0, 0, 1)
coll._edgecolors[event.ind,:] = (1, 0, 0, 1)
fig.canvas.draw()

fig.canvas.mpl_connect('pick_event', on_pick)
plt.show()
``````

## Point opacity relative to depth matplotlib 3D point plot

By : Lemal
Date : March 29 2020, 07:55 AM
this one helps. It looks like you're out of luck on this, it seems plot does not have the depthshade=True feature. I think the problem is plot does not let you set a different color (or alpha value) for each points in the way scatter does, which I guess is how depthshade is applied.
A solution is to loop over all points and set colour one by one, together with the mpl_toolkits.mplot3d.art3d.zalpha helper function to give depth.
code :
``````import mpl_toolkits
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

n = 100
xs = np.random.rand(n)
ys = np.random.rand(n)
zs = np.random.rand(n)
color = [1,0,0,1]

#Get normal to camera
alpha= ax.azim*np.pi/180.
beta= ax.elev*np.pi/180.
n = np.array([np.cos(alpha)*np.sin(beta),
np.sin(alpha)*np.cos(beta),
np.sin(beta)])
ns = -np.dot(n, [xs, ys, zs])
cs = mpl_toolkits.mplot3d.art3d.zalpha(color, ns)

for i in range(xs.shape[0]):
ax.plot([xs[i]], [ys[i]], [zs[i]], 'o', color=cs[i])

plt.show()
``````
``````def Update(event):
#Update normal to camera
alpha= ax.azim*np.pi/180.
beta= ax.elev*np.pi/180.
n = np.array([np.cos(alpha)*np.sin(beta),
np.sin(alpha)*np.cos(beta),
np.sin(beta)])
ns = -np.dot(n, [xs, ys, zs])
cs = mpl_toolkits.mplot3d.art3d.zalpha(color, ns)
for i, p in enumerate(points):
p[0].set_alpha(cs[i][3])

fig.canvas.mpl_connect('draw_event', Update)

points = []
for i in range(xs.shape[0]):
points.append(ax.plot([xs[i]], [ys[i]], [zs[i]], 'o', color=cs[i]))
``````

## Annotating every data point in scatter plot in matplotlib python

By : Raphael Diniz
Date : March 29 2020, 07:55 AM
should help you out I think the problem comes from the fact that your "salary" and "bonus" columns are interpreted as strings. Hence when you xy + (0.02, 5), it thinks that you are trying to concatenate the string (xy) with a tuple. I think you should try and cast those columns to floats or integers depending on your case.
 Privacy Policy - Terms - Contact Us © festivalmusicasacra.org