logo
down
shadow

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


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 : facebook icon twitter icon
How can I control the color and opacity of each point in a python scatter plot?

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

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

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

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

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.
Related Posts Related Posts :
  • Filtering from data
  • Where is the problem about selenium with python?
  • ansible custom filter fails when importing python library
  • How to assign the label of one column to the new one based on group maximum in pandas
  • What is the best approach for isolating a single area of similar colour?
  • Creating multiple clients for topics
  • Why is my 'for loop', despite iterating over all keys, only acting on the last one?
  • Can someone tell me what's wrong, when I run it the browsers says "This site can’t be reached"
  • Error in setting up mitmproxy on alpine 3.9
  • From traditional loop to list comprehension
  • Django celery unregistered task | relative imports
  • How to add elements in a multi dimensional array
  • Async await with sqs receive messages not working properly
  • What is definition of 'NAME' in Python grammar
  • Easy method to move rows from df to another with coditions?
  • Changing the size of only a single plot in matplotlib, without altering figure parameters
  • Fastest way to use Vision API on 10,000+ images with python
  • How to install nvidia apex on Google Colab
  • Random numbers Continuous in python
  • Fetching data after a certain time interval(10 sec) from a continuously increasing database like mysql using flask
  • Using VLOOKUP with merge in Python
  • Calculate geographical distance between 5 cities with all the possible combinations of each city
  • How to filter a pandas dataframe using multiple partial strings?
  • Pygame- make bullet shoot toward cursor direction
  • Create SEQUENCE based dictionary from list
  • How to fix broken link from Django MEDIA_ROOT?
  • How can I display the current time left in a timer in a label?
  • Compute number of occurance of each value and Sum another column in Pandas
  • How to separate the prefix in words that are 'di'?
  • Handling network errors from an external API across an application
  • Want a pandas Series of Trips Completed to count(Request) ratio for each hour as index for the given dataframe
  • Access dict keys and list elements by same index to loop over and assign values
  • Find rows from the same dataframe based on condition
  • Read only specific part first two lines from text file in python
  • Python How to convert string to dataframe?
  • How to fix this my error code program? I use Python 3.6
  • Is there a way of getting this string down to 3 words?
  • Large difference between overall F Score for a custom Spacy NER model and Individual Entity F Score
  • Drop rows where timestamps are older than subsequent row
  • Implement a bottle spin
  • Unable to convert widows epoch time to normal date time
  • Values from a XML file
  • PyAudio readframes not ending when wav file completes
  • Could not load the module
  • How to change datetime.datetime(2012, 1, 1, 0, 0) to 1/1/2012 in Python?
  • How to create ASN.1 Sequence without NamedType?
  • How to locate specific sequences of words in a sentence efficiently
  • How can I generate a multi-step process in Django without changing pages (w/out a new request)?
  • Why does this list comprehension only "sometimes" work?
  • send html report with row collapsed
  • How to define a type hint to a argument (the argument's value is a class, all expected value is a subclass of a certain
  • How do I send a styled pandas DataFrame by e-mail without losing the format?
  • How to view/average a groupby dataframe when the data is a string?
  • Django 2.2 staticfiles do not work in development
  • Flag to enable/disable numba JIT compilation?
  • Trying to split byte in a byte array into two nibbles
  • Error in Query - missing FROM-clause entry for table - SQL
  • Reading double c structures of Dll with Ctypes in Python
  • Autofill missing row in database based on missing time range
  • Get the max of a nested dictionary
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org