<jupyter_start><jupyter_text>Chart ConfigurationAltair provides a number of hooks to configure the look of your chart; we don't have time to go into all the available options here, but it is useful to know where and how such configuration settings can be accessed and explored.In general, there are two or three places where the look of a chart can be controlled, each with a greater priority than the last.1. **Top Level Chart Config**. At the top level of an Altair chart, you can specify configuration settings that will apply to every panel or layer in the chart.2. **Local Configuration Settings**. The top-level settings can be over-ridden locally, by specifying local configuration3. **Encoding Values**. If an encoding value is specified, it will take highest precedance, and override the other options.Let's see an example.<jupyter_code>import altair as alt

# Altair plots render by default in JupyterLab and nteract

# Uncomment/run this line to enable Altair in the classic notebook (not in JupyterLab)
# alt.renderers.enable('notebook')

# Uncomment/run this line to enable Altair in Colab
# alt.renderers.enable('colab')
import numpy as np
import pandas as pd
np.random.seed(42)

data = pd.DataFrame(np.random.randn(100, 2), columns=['x', 'y'])<jupyter_output><empty_output><jupyter_text>Example 1: Controlling Marker PropertiesSuppose you would like to control the color of the markers in a scatter plot: let's see each of the three options for doing this. We'll use a simple datasets of normally-distributed points:<jupyter_code>alt.Chart(data).mark_point().encode(
    x='x:Q',
    y='y:Q'
)<jupyter_output><empty_output><jupyter_text>Top-level configurationAt the top level, Altair has a ``configure_mark()`` method that allows you to adjust a large number of configuration settings for marks in general, as well as a ``configure_point()`` property that specifically adjusts the properties of points.You can see the availale options in Jupyter in the documentation string, accessed with a question mark:<jupyter_code>alt.Chart.configure_point?<jupyter_output><empty_output><jupyter_text>This top-level configuration should be thought of as a chart theme: they are the default settings for the aesthetics of all chart elements.Let's use ``configure_point`` to set some properties of points:<jupyter_code>alt.Chart(data).mark_point().encode(
    x='x:Q',
    y='y:Q'
).configure_point(
    size=200,
    color='red',
    filled=True
)<jupyter_output><empty_output><jupyter_text>Many local configurations are available; you can use Jupyter's tab-completion and help features to explore them<jupyter_code># type alt.Chart.configure then the TAB key to see available configurations
alt.Chart.configure_<jupyter_output><empty_output><jupyter_text>Local Mark ConfigurationWithin the ``mark_point()`` method, you can pass local configurations that will override the top-level configuration settings.The arguments are the same as that of ``configure_mark``.<jupyter_code>alt.Chart(data).mark_point(color='green', filled=False).encode(
    x='x:Q',
    y='y:Q'
).configure_point(
    size=200,
    color='red',
    filled=True
)<jupyter_output><empty_output><jupyter_text>Notice here that the "color" and "fill" configurations are overridden by the local configurations, but the "size" remains the same as before.  Encoding ConfigurationFinally, the highest precedence setting is the "encoding" setting. Here let's set the color to "steelblue" within the encoding:<jupyter_code>alt.Chart(data).mark_point(color='green', filled=False).encode(
    x='x:Q',
    y='y:Q',
    color=alt.value('steelblue')
).configure_point(
    size=200,
    color='red',
    filled=True
)<jupyter_output><empty_output><jupyter_text>Now this is a bit of a contrived example, but it's useful to help grasp the various places that properties of marks can be set.  Example 2: Chart and Axis TitlesChart and axis titles are set automatically based on the data source, but sometimes it is useful to change them.For example, here is a histogram of the above data:<jupyter_code>alt.Chart(data).mark_bar().encode(
    x=alt.X('x', bin=True),
    y=alt.Y('count()')
)<jupyter_output><empty_output><jupyter_text>We can explicitly set the axis titles using the ``title`` argument to the encoding:<jupyter_code>alt.Chart(data).mark_bar().encode(
    x=alt.X('x', bin=True, title='binned x values'),
    y=alt.Y('count()', title='counts in x')
)<jupyter_output><empty_output><jupyter_text>Likewise, we can set the ``title`` property of the chart within the chart properties:<jupyter_code>alt.Chart(data).mark_bar().encode(
    x=alt.X('x', bin=True, title='binned x values'),
    y=alt.Y('count()', title='counts in x')
).properties(
    title='A histogram'
)<jupyter_output><empty_output><jupyter_text>Example 3: Axis PropertiesIf you would like to set the properties of the axes, including grid lines, you can use the encodings'``axis`` argument.<jupyter_code>alt.Chart(data).mark_bar().encode(
    x=alt.X('x', bin=True, axis=alt.Axis(labelAngle=45)),
    y=alt.Y('count()', axis=alt.Axis(labels=False, ticks=False, title=None))
)<jupyter_output><empty_output><jupyter_text>Note that some of these values can be adjusted at the top-level configuration as well, if you want them to apply to the chart as a whole. For example:<jupyter_code>alt.Chart(data).mark_bar().encode(
    x=alt.X('x', bin=True),
    y=alt.Y('count()', axis=alt.Axis(labels=False, ticks=False, title=None))
).configure_axisX(
    labelAngle=45
)<jupyter_output><empty_output><jupyter_text>Example 4: Scale properties & axis limitsEach encoding also has a ``scale`` that allows you to adjust things like axis limits and other scale properties.<jupyter_code>alt.Chart(data).mark_point().encode(
    x=alt.X('x:Q', scale=alt.Scale(domain=[-5, 5])),
    y=alt.Y('y:Q', scale=alt.Scale(domain=[-5, 5])),
)<jupyter_output><empty_output><jupyter_text>Note that if you shrink the scale to smaller than the range of the data, the data will extend beyond the scale by default:<jupyter_code>alt.Chart(data).mark_point().encode(
    x=alt.X('x:Q', scale=alt.Scale(domain=[-3, 1])),
    y=alt.Y('y:Q', scale=alt.Scale(domain=[-3, 1])),
)<jupyter_output><empty_output><jupyter_text>Not hiding data is a useful default in exploratory visualization, because it prevents you from inadvertently missing data points.If you would like the markers to be clipped beyond the range of the scales, you can set the ``clip`` property of marks:<jupyter_code>alt.Chart(data).mark_point(clip=True).encode(
    x=alt.X('x:Q', scale=alt.Scale(domain=[-3, 1])),
    y=alt.Y('y:Q', scale=alt.Scale(domain=[-3, 1])),
)<jupyter_output><empty_output><jupyter_text>Another useful approach is to instead "clamp" the data to the extremes of the scale, keeping it visible even when it is out of range:<jupyter_code>alt.Chart(data).mark_point().encode(
    x=alt.X('x:Q', scale=alt.Scale(domain=[-3, 1], clamp=True)),
    y=alt.Y('y:Q', scale=alt.Scale(domain=[-3, 1], clamp=True)),
).interactive()<jupyter_output><empty_output><jupyter_text>Example 5: Color ScalesSometimes it's useful to manually adjust a color scale used<jupyter_code>from vega_datasets import data
weather = data.seattle_weather()
weather.head()
alt.Chart(weather).mark_point().encode(
    x='date:T',
    y='temp_max:Q',
    color='weather:N'
)<jupyter_output><empty_output><jupyter_text>You can change the color scheme by using the color scale property, and by referencing any of [Vega's named color schemes](https://vega.github.io/vega/docs/schemes/reference):<jupyter_code>alt.Chart(weather).mark_point().encode(
    x='date:T',
    y='temp_max:Q',
    color=alt.Color('weather:N', scale=alt.Scale(scheme="dark2"))
)<jupyter_output><empty_output><jupyter_text>Alternatively, you can create your own color scheme by specifying a color domain and range:<jupyter_code>colorscale = alt.Scale(domain=['sun', 'fog', 'drizzle', 'rain', 'snow'],
                       range=['goldenrod', 'gray', 'lightblue', 'steelblue', 'midnightblue'])

alt.Chart(weather).mark_point().encode(
    x='date:T',
    y='temp_max:Q',
    color=alt.Color('weather:N', scale=colorscale)
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12236906510034264, 'fraction_numerical': 0.0053842388644150755, 'mean_word_length': 5.8393305439330545, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 77, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '19', 'dir': 'jupyter-structured-clean-dedup', 'id': '195036', 'license': 'MIT', 'n_tokens_mistral': 2647, 'n_tokens_neox': 2545, 'n_words': 813, 'path': 'notebooks/08-Configuration.ipynb', 'repo_name': 'ojosem/altair-tutorial', 'size': '8172'}