Load cryptocurrency prices directly from the web and create an interactive candlestick chart using Altair.

Video

Follow along with the exercise

Pre-requisites

Installed and configured miniconda. See either Up and running with miniconda and pycharm on macOS or Up And Running With Miniconda And PyCharm On Windows.

After that, get the required code and notebook from the github repo by doing this:

git clone git@github.com:cpbotha/altair_basic_charting.git
cd altair_basic_charting
conda env update
conda activate vxuni_altair
jupyter lab

You should now be looking at a live version of the notebook in your browser.

Overview 00:16

  • Load tabular data from the web: Cryptocurrency prices.
  • Create candlestick + volume charts using Altair.
  • Compose charts.
  • Digging into Altair source and Vega lite docs in order to:
  • Make the composite chart pannable and zoomable.

Load tabular data from the web 00:46

  • Copy and paste into spreadsheet, import that into pandas.
  • Even quicker: pandas.read_html()

What is a candlestick chart? 04:58

  • Candlesticks show opening, closing, high and low prices.
  • Green when price has gone up, red otherwise.

Building candlestick charts with Altair 06:39

  • Start with base altair.Chart() 08:53
  • What are encodings is Altair? 09:41
  • What are marks? 10:38
  • What are scales? 11:39
  • Using an altair.condition() to encode an input value as a color. 12:56
  • Composing charts. 16:40

Adding pan and zoom to the composite chart 17:47

  • Straight-forward chart.interactive() does not work here, because composite!
  • Find clues in the Altair source using the IDE. 19:16
  • Find the answer in the Vega docs! 20:00
  • The solution: resolve_scale(x='shared') 21:30
  • Query the Vega representation of the Altair chart. 23:53

Conclusion 25:23

  • Summary.
  • See you next time!

Leave a Reply

Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.

Not readable? Change text. captcha txt

Start typing and press Enter to search