R color scatter plot points based on values
By : sury
Date : March 29 2020, 07:55 AM
Hope this helps Best thing to do here is to add a column to the data object to represent the point colour. Then update sections of it by filtering. code :
data< read.table('sample_data.txtt', header=TRUE, row.name=1)
# Create new column filled with default colour
data$Colour="black"
# Set new column values to appropriate colours
data$Colour[data$col_name2>=3]="red"
data$Colour[data$col_name2<=1]="blue"
# Plot all points at once, using newly generated colours
plot(data$col_name1,data$col_name2, ylim=c(0,5), col=data$Colour, ylim=c(0,10))

How to give color range to scatter plot for up and down values
By : Chintan_sec
Date : March 29 2020, 07:55 AM
it fixes the issue Here is a solution creating a new variable corresponding to color groups before the ggplot : code :
set.seed(1)
df = data.frame(x = rnorm(1000,1,10))
df$y = df$x + rnorm(1000,1,5)
df$col = NA
df$col[(df$x  df$y) > 5] = "g1"
df$col[(df$x  df$y) < 5 & (df$x  df$y) > 5] = "g2"
df$col[(df$x  df$y) < 5] = "g3"
ggplot(df, aes(x, y, color = col)) + geom_point()
library(plyr)
df_labels = ddply(df, "col", summarise, n = n())
ggplot(df, aes(x, y, color = col)) + geom_point() +
scale_color_manual(labels = df_labels$n, values = c("g1" = "red", "g2" = "blue", "g3" = "green"))

NaN values as special color in pyplot scatter plot
By : Deepthi Holla
Date : March 29 2020, 07:55 AM
wish help you to fix your issue The reason that your NaN values are not plotted is that matplotlib's scatter currently filters them out before giving them to the colormap. To show the NaN entries you can manually assign them a dummy value with a special meaning. For example, because your list is in the range [0, 1] you could define that any value > 1 get a special color. For this you will have to fix the range of the coloraxis, and specify a color for entries outside this range (in this case higher than the maximum). code :
cax = ax.scatter(...)
cax.cmap.set_over('y') # assigns yellow to any entry >1
cax.set_clim(0, 1) # fixes the range of 'normal' colors to (0, 1)
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
numPoints = 20
nanFrequency = 3
xVec = np.arange(numPoints, dtype=float)
yVec = xVec
colorVec = np.linspace(0,1,numPoints)
colorVec[range(0, numPoints, nanFrequency)] = np.NaN
cmap = mpl.colors.LinearSegmentedColormap.from_list("BlueRedColormap", ["b", "r"], numPoints)
# 
fig, axes = plt.subplots(nrows=2, figsize=(8, 2*6))
# 
ax = axes[0]
ax.scatter(xVec, yVec, c=colorVec, cmap=cmap)
ax.set_xlim([0, 20])
ax.set_ylim([0, 20])
# 
ax = axes[1]
colorVec[np.isnan(colorVec)] = 2.0
cax = ax.scatter(xVec, yVec, c=colorVec, cmap=cmap)
cax.cmap.set_over('y')
cax.set_clim(0, 1)
ax.set_xlim([0, 20])
ax.set_ylim([0, 20])
# 
plt.show()

How to make a scatter plot with varying scatter size and color corresponding to a range of values from a dataframe?
By : user3367289
Date : March 29 2020, 07:55 AM
hope this fix your issue You could use pandas.cut to create a couple of helper columns in df based on your color and size mappings. This should make it easier to pass these arguments to pyplot.scatter. N.B. It's worth noting that the values you've chosen for size may not distinguish the markers very well in the plot  it'd be worth experimenting with different sizes until you get the desired results code :
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
df['color'] = pd.cut(df['Depth'], bins=[np.inf, 30, 40, 60, np.inf], labels=['red', 'blue', 'black', 'yellow'])
df['size'] = pd.cut(df['Magnitude'], bins=[np.inf, 2, 3, 4, np.inf], labels=[1, 1.5, 2, 2.5])
plt.scatter(df['Lon'], df['Lat'], c=df['color'], s=df['size'])
def magnitude_size(magnitude):
if magnitude < 2 :
return 1
if magnitude >= 2 and magnitude < 3 :
return 1.5
if magnitude >= 3 and magnitude < 4 :
return 2
if magnitude >= 4 :
return 2.5
def depth_color(depth):
if depth < 30 :
return 'red'
if depth >= 30 and depth < 40 :
return 'blue'
if depth >= 40 and depth < 60 :
return 'black'
if depth >= 60 :
return 'yellow'
if np.isnan(depth):
return 'green'
di = {
'size': df.Magnitude.apply(magnitude_size),
'color' : df.Depth.apply(depth_color)
}
plt.scatter(df.Lon,df.Lat,c=di['color'],s=di['size'])

How do you map a 3d matrix to color values in a 3d scatter plot using matplotlib?
By : adrian myles
Date : March 29 2020, 07:55 AM
may help you . The scatter needs the same number of points than the color array c. So for 1000 colors you need 1000 points.

