logo
down
shadow

Value Error with color array when slicing values for scatter plot


Value Error with color array when slicing values for scatter plot

By : Chien-Sheng Wu
Date : November 21 2020, 12:01 PM
hop of those help? Your colour list should be the same length as your data. So you need to apply the same slice.
code :
timePlot = ax.scatter(x[::5], y[::5], s=50, c=timeList[::5], 
                      marker = marker.next(), edgecolors='none', 
                      norm=cNorm, cmap = plt.matplotlib.cm.jet)


Share : facebook icon twitter icon
R color scatter plot points based on values

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

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

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 color-axis, 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("Blue-Red-Colormap", ["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?

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?

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.
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