Setting the Color for an Individual Data Point

Python & matplotlib - changing the color of individual points

In this case, you need your artist to be each point instead of ta collection because you want them to behave separately. So, you can iterate over all your points and make many lines, one at a time. This way, changing the plot's color will only affect the selected patch. Follows an example:

import matplotlib.pyplot as plt
import numpy as np
from numpy.random import rand

# simple picking lines
def onpick1(event):
thisline = event.artist #Get the clicked line OR line collection
thisline._color = '#DC143C' #Set to new color, in this case must be hsv
thisline._axes.figure.canvas.draw() #update the plot
thisline._axes.figure.canvas.flush_events()
fig, ax1 = plt.subplots()
data = rand(10, 2) #Random points for demonstration
for data_point in data:
line, = ax1.plot(data_point[0], data_point[1], 'o', picker=2, c='yellow') #2 points tolerance
fig.canvas.mpl_connect('pick_event', onpick1)
plt.show()

How to change the color of points on data plot?

As Jon Spring pointed out, scale_colour_manual() is the way to do this. Here is an example:

library(ggplot2)
library(dplyr)

mtcars %>%
mutate(win = ifelse(cyl <= 4, 1, 0)) %>%
ggplot(aes(x = wt, y = mpg, col = factor(win))) +
geom_point() +
scale_colour_manual(values = c("1" = "green",
"0" = "red"))

Sample Image

Created on 2022-03-11 by the reprex package (v2.0.1)

Change color of only one data point in gnuplot

Edited to show variable pointsize also

If I understand your data format correctly:

set linetype 11 lc "orange"
set linetype 12 lc "white"

set style data points
do for [i=0:N] {
plot "positions.txt" index i using 1:2:(column(0)>0 ? 0.5 : 2.0):(column(0)>0 ? 12 : 11) pt 7 ps variable lc variable
}

Variable color (if used) is always taken from the very last using column. Other variable properties work back from there.

How to change colors of specific data points in a series of a chart?

I would suggest adding an extra series to your chart and changing the color set on that.



Related Topics



Leave a reply



Submit