question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting the size of mark_rect

See original GitHub issue

My question is regarding setting the size (width and height) of each of the cells in mark_rect(). How can we do that such that the size is fixed, and the overall heatmap just gets bigger if we have more boxes to show?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jakevdpcommented, Sep 18, 2020

You can do this with mark_square() - this is akin to mark_point() and mark_circle() in that it generates points that can have a size encoding, whereas rect generates rectangles whose size is controlled by x,x2,y,y2 encodings:

import altair as alt
import numpy as np
import pandas as pd

# Compute x^2 + y^2 across a 2D grid
x, y = np.meshgrid(range(-10, 10), range(-5, 5))
z = x ** 2 + y ** 2

# Convert this grid to columnar data expected by Altair
source = pd.DataFrame({'x': x.ravel(),
                     'y': y.ravel(),
                     'z': z.ravel()})

alt.Chart(source).mark_square().encode(
    x='x:O',
    y='y:O',
    color='z:Q',
    size='z:Q'
)

visualization (37)

2reactions
RoyalTScommented, Nov 30, 2020
import altair as alt
import numpy as np
import pandas as pd

# Compute x^2 + y^2 across a 2D grid
x, y = np.meshgrid(range(-10, 10), range(-5, 5))
z = x ** 2 + y ** 2

# Convert this grid to columnar data expected by Altair
source = pd.DataFrame({'x': x.ravel(),
                     'y': y.ravel(),
                     'z': z.ravel()})

alt.Chart(source).mark_rect(size=5).encode(
    x='x:O',
    y='y:O',
    color='z:Q'
).configure_scale(
    rangeStep=10
)

This seems to have stopped working. I get

SchemaValidationError: Invalid specification

        altair.vegalite.v4.schema.core.ScaleConfig, validating 'additionalProperties'

        Additional properties are not allowed ('rangeStep' was unexpected)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Adjust Marker Size in Matplotlib? - GeeksforGeeks
We can adjust marker size in plots of matplotlib either by specifying the size of the marker in either plot method or scatter...
Read more >
Company size: Why market capitalization matters - Merrill Edge
Market cap is a method of measuring the size of a company and can help guide your investment strategy as many investors choose...
Read more >
How to Write a Market Analysis - Bplans Blog
This is where you'll outline the current state of your industry overall and where it's headed. Relevant industry metrics like size, trends, life...
Read more >
Perfect Competition: Examples and How It Works - Investopedia
Pure or perfect competition is a theoretical market structure in which a number of criteria such as perfect information and resource mobility are...
Read more >
matplotlib - pyplot scatter plot marker size - Stack Overflow
The marker size. s: size in points^2. It is a scalar or an array of the same length as x and y. What...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found