# category: bar charts
import altair as alt
import pandas as pd

source = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})

bars = alt.Chart(source).mark_bar().encode(
    y='a',
    x='b'
)

text = bars.mark_text(
    align='left',
    baseline='middle',
    dx=3
).encode(
    text='b'
)

bars + text

# category: bar charts
import altair as alt
from vega_datasets import data

source = data.wheat.url

bars = alt.Chart(source).mark_bar().encode(
    x='wheat:Q',
    y="year:O"
)

text = bars.mark_text(
    align='left',
    baseline='middle',
    dx=3  # Nudges text to right so it doesn't appear on top of the bar
).encode(
    text='wheat:Q'
)

(bars + text).properties(height=900)

Standardize bar chat with labels example to use source consistent with other examples
DOC: Standardize bar chat with labels example to use source consistent with other examples
  # category: bar charts
  import altair as alt
- import pandas as pd
+ from vega_datasets import data
  
+ source = data.wheat.url
- source = pd.DataFrame({
-     'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
-     'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
- })
  
  bars = alt.Chart(source).mark_bar().encode(
-     y='a',
-     x='b'
+     x='wheat:Q',
+     y="year:O"
  )
  
  text = bars.mark_text(
      align='left',
      baseline='middle',
-     dx=3
+     dx=3  # Nudges text to right so it doesn't appear on top of the bar
  ).encode(
-     text='b'
+     text='wheat:Q'
  )
  
- bars + text
+ (bars + text).properties(height=900)
  
Standardize bar chat with labels example to use source consistent with other examples
## Code Before:
# category: bar charts
import altair as alt
import pandas as pd

source = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})

bars = alt.Chart(source).mark_bar().encode(
    y='a',
    x='b'
)

text = bars.mark_text(
    align='left',
    baseline='middle',
    dx=3
).encode(
    text='b'
)

bars + text

## Instruction:
Standardize bar chat with labels example to use source consistent with other examples
## Code After:
# category: bar charts
import altair as alt
from vega_datasets import data

source = data.wheat.url

bars = alt.Chart(source).mark_bar().encode(
    x='wheat:Q',
    y="year:O"
)

text = bars.mark_text(
    align='left',
    baseline='middle',
    dx=3  # Nudges text to right so it doesn't appear on top of the bar
).encode(
    text='wheat:Q'
)

(bars + text).properties(height=900)
