Build a Revenue and Stock Price Combo Chart with Python
Financial charts often combine metrics that live on completely different scales. For example: company revenue measured in billions of dollars, stock prices measured in tens or hundreds of dollars. I wanted to recreate the infographic style seen on Visual Capitalist using pure Python and SVG. The chart combines: annual revenue as bars, monthly stock prices as a line, a secondary axis, a clipped gradient area inside the revenue columns. One of the most interesting parts is the clipping effect. The stock-price area spans the entire chart, but SVG clipping reveals it only inside the revenue bars: stock_layer = dp . G (). append ( dp . Path ( d = area_generator ( stock_points ), fill = " url(#area-gradient) " , clip_path = " url(#revenue-clip) " , ) ) This creates a visual connection between the two datasets without sacrificing readability. The chart is generated entirely as SVG using pyDreamplet, which means: resolution independent output, easy customization, structured graphics instead of pixels, perfect for reports, dashboards, and infographics. A few design decisions helped keep the chart readable: bars and lines use different visual encodings, each series has its own color, only one axis draws gridlines, labels stay outside the plotting area, decorative elements never compete with the data. The complete tutorial walks through: loading the data, building scales, generating bars, drawing the stock-price curve, creating clipping paths, embedding SVG icons, exporting the final graphic. 👉 Full step-by-step tutorial: https://py.dreamplet.com/tutorials/combo-chart 👉 Source code: https://github.com/marepilc/pydreamplet-showcase/tree/master/scripts/combo_chart
Comments
No comments yet. Start the discussion.