ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 26 Jan 2024 02:59:00 +0100Draw a list of continuously colored pointshttps://ask.sagemath.org/question/75651/draw-a-list-of-continuously-colored-points/I have a list of point and use list_point to draw it. Let’s say
L=[[k,sqrt(k)] for k in range (1000)]
list_plot(L)
I'd like to color the points in a continuous way, to remember the order in which they were drawn. Let's say from the black for the first point on the list to the red for the last.
How can I achieve my goal?Thu, 25 Jan 2024 11:09:24 +0100https://ask.sagemath.org/question/75651/draw-a-list-of-continuously-colored-points/Answer by dan_fulea for <p>I have a list of point and use list_point to draw it. Let’s say</p>
<pre><code>L=[[k,sqrt(k)] for k in range (1000)]
list_plot(L)
</code></pre>
<p>I'd like to color the points in a continuous way, to remember the order in which they were drawn. Let's say from the black for the first point on the list to the red for the last.</p>
<p>How can I achieve my goal?</p>
https://ask.sagemath.org/question/75651/draw-a-list-of-continuously-colored-points/?answer=75659#post-id-75659Here is a way, i tried in hurry:
N = 1000
R = range(N)
def myrgbcolor(k):
# you may try also some other functions to have variation of colors
# return hue(1/4 + k/2/N)
# return hue(k/N)
# return Color(1 - k^2/N^2, 0, 0)
return Color(1 - k/N, 0, 0) # r, g, b entries in Color in interval (0, 1), red is (1, 0, 0), black is (0, 0, 0)
points = [point((k, sqrt(k)), rgbcolor=myrgbcolor(k)) for k in R]
G = sum(points)
# viewer.png_viewer('feh') # for me - just to prevent the default firefox to get a new tab...
G.show()
![sqrt function plotted from red to black](/upfiles/17062340387389112.png)
Fri, 26 Jan 2024 02:59:00 +0100https://ask.sagemath.org/question/75651/draw-a-list-of-continuously-colored-points/?answer=75659#post-id-75659