Particles
- D3Blocks.particles(text: str, radius: int = 3, collision: float = 0.05, fontsize: int = 180, spacing: int = 8, cmap: str = 'Turbo', color_background: str = '#000000', shape: str = 'circle', mouse_radius: float = 50, square_scale: float = 1.5, title: str = 'Particles - D3blocks', filepath: str = 'particles.html', figsize=[900, 200], showfig: bool = True, notebook: bool = False, save_button: bool = False, return_html: bool = False, overwrite: bool = True)
Particles block.
The particles plot is to turn any word into an interactive visualization. With a mouse-move or touch, the particle bounce and then return to their original place. Various properties can be changed such as the bouncing, particle size, and colors. The original javascript is forked from Ian Johnson’s Block.
- Parameters:
text (str) – String to be visualized
radius (float, optional (default: 3)) – Size of the particles.
collision (float, optional (default: 0.1)) – Response of the interaction. Higher means that more collisions are prevented.
fontsize (int, optional (default: 250)) – Text fontsize. When increasing: also increase width and slighly the spacing.
spacing (int, optional (default: 10)) – The number of particles that fit in the text. A larger spacing reults in less particles. A smaller spacing reults in more particles.
cmap (str, optional (default: 'Set2')) –
- Color schemes can be found at the references.
’Turbo’, ‘Rainbow’, ‘Blues’, ‘Reds’, ‘Inferno’, ‘Magma’
color_background (str, optional (default: '#000000')) – Background color.
shape (str, optional (default: 'circle')) –
- Particle shape.
’circle’: round particles
’square’ (or ‘rect’): square particles
mouse_radius (float, optional (default: 50)) – Radius of the invisible mouse disturbance that pushes particles aside on hover. Larger = wider disturbance; smaller = tighter.
square_scale (float, optional (default: 1.5)) – Size multiplier for square particles (width/height = radius * square_scale). Only used when
shape='square'. The original look uses 1.5.title (str, optional (default: None)) – Title of the figure.
filepath (str, optional (default: user temp directory)) –
- File path to save the output.
Temporarily path: ‘d3blocks.html’
Relative path: ‘./d3blocks.html’
Absolute path: ‘c://temp//d3blocks.html’
None: Return HTML content.
figsize (tuple, optional (default: (800, 600))) – Size of the figure in the browser, [width, height]. Use
[None, None](or either dimNone) to fill the full browser window.showfig (bool, optional (default: True)) – Open the window to show the particles.
notebook (bool, optional) –
True: Use IPython to show chart in notebooks.
False: Do not use IPython.
save_button (bool, (default: True)) –
True: Save button is shown in the HTML to save the image in svg.
False: No save button is shown in the HTML.
return_html (bool, (default: False)) –
True: Return html
False: Nothing is returned
overwrite (bool, optional (default: True)) –
True: Overwrite the output html in the destination directory.
False: Do not overwrite
- Return type:
None.
Examples
>>> # Load d3blocks >>> from d3blocks import D3Blocks >>> # >>> # Initialize >>> d3 = D3Blocks() >>> # >>> # Create chart with defaults >>> d3.particles('D3blocks') >>> # >>> # Create customized chart >>> d3.particles('D3Blocks', filepath='D3Blocks.html', collision=0.05, spacing=7, figsize=[750, 150], fontsize=130, cmap='Turbo', color_background='#ffffff')
References
Input Data
The input is a text string, such as “D3Blocks”