Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

multicolor points in one legend entry python

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.legend_handler import HandlerLineCollection
from matplotlib.collections import LineCollection

class HandlerColorLineCollection(HandlerLineCollection):
    def create_artists(self, legend, artist ,xdescent, ydescent,
                        width, height, fontsize,trans):
        x = np.linspace(0,width,self.get_numpoints(legend)+1)
        y = np.zeros(self.get_numpoints(legend)+1)+height/2.-ydescent
        points = np.array([x, y]).T.reshape(-1, 1, 2)
        segments = np.concatenate([points[:-1], points[1:]], axis=1)
        lc = LineCollection(segments, cmap=artist.cmap,
                     transform=trans)
        lc.set_array(x)
        lc.set_linewidth(artist.get_linewidth())
        return [lc]

t = np.linspace(0, 10, 200)
x = np.cos(np.pi * t)
y = np.sin(t)
points = np.array([x, y]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)

lc = LineCollection(segments, cmap=plt.get_cmap('copper'),
                    norm=plt.Normalize(0, 10), linewidth=3)
lc.set_array(t)

fig, ax = plt.subplots()
ax.add_collection(lc)

plt.legend([lc], ["test"],
    handler_map={lc: HandlerColorLineCollection(numpoints=4)}, framealpha=1)

ax.autoscale_view()
plt.show()
Comment

PREVIOUS NEXT
Code Example
Typescript :: terminal update file metadata 
Typescript :: dwayne johnson maui 
Typescript :: useappdispatch 
Typescript :: typescript d ts meaning 
Typescript :: puts with details ruby 
Typescript :: ngx-numeral 
Typescript :: how to show account related contacts on click of a button using lightnig components 
Typescript :: Find more than one child node with `children` in ResizeObserver. Please use ResizeObserver.Collection instead in React/ant design [antd] 
Typescript :: how to make a class that inherits from another file class in python 
Typescript :: when 2 emits on a same chatroom at a time only one is working using socket.io 
Typescript :: palindromic no. 
Typescript :: Using TypeScript generic with `...rest` operator 
Typescript :: angular TS2377 
Typescript :: typescript array of mixed type 
Typescript :: corpses:2249 Livewire: The published Livewire assets are out of date 
Typescript :: how to loop through a specific number of elements in a list python 
Typescript :: enum to number typescript 
Typescript :: what is .align mips 
Typescript :: how to pass data between requests in api 
Typescript :: em is relative to its font size 
Typescript :: attend 
Typescript :: what to do when testing new feature with limited information 
Typescript :: spade operator typescript 
Typescript :: quizlet In converting an entrepreneurial business script into an enterprise value chain, the financing process of the value chain is usually made up of two different scenes 
Typescript :: create a square class that inherits from rectangle. 
Typescript :: TypeScript interface for object with arbitrary numeric property names? 
Typescript :: 0 
Typescript :: how to set value to readonly property in typescript while unit testing 
Typescript :: can blue jays tickets still be printed 
Typescript :: flutter: Error: google_fonts was unable to load font LobsterTwo-Bold because the following exception occured: 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =