Charts and image files.
Turn measurements into honest charts and understand images as pixel data.
Start here.
A chart maps data values to visual positions. In a line chart, ordered x values such as weeks are placed along one axis and measurements along the other; connecting them suggests change across that order. A bar chart compares separate categories. The data and the drawing are separate: changing an axis scale or omitting labels can change what a viewer infers even when the underlying numbers stay the same.
matplotlib is a third-party plotting library. A figure is the whole output canvas, and axes are the plotting area with scales and labels. The example creates both, passes lists of weeks and completed counts to plot, labels the axes, then saves the figure as a PNG. The lists must correspond by position: week 1 pairs with the first count, week 2 with the second, and so on.
An image is a rectangular grid of pixels. Each pixel stores color information, and its coordinate identifies a place in that grid. Pillow can open, create, crop, resize, and save common image files. PNG can preserve sharp edges and transparency; JPEG is often smaller for photographs but loses some detail. Saving an image encodes pixel data into a file, while displaying it is a separate step. Text and important chart values should remain understandable without relying only on color.
Build the model.
A chart is an argument about data. Before choosing colours, decide what comparison a reader should make. A line chart shows change along an ordered axis; a bar chart compares categories. Label units and axes, keep scales honest, and show enough context that a viewer can tell whether a difference is meaningful.
An image is a grid of pixels with a width, height, and colour mode. A pixel's coordinates start at the top-left in common Python image libraries. Cropping, resizing, and drawing change that grid; saving encodes it into a format such as PNG or JPEG. The chosen format affects quality, transparency, and file size.
How it works.
matplotlib's pyplot offers a compact chart workflow: create a figure and axes, plot values, set labels, then save the figure. Keep the data transformation separate so you can inspect the numbers before plotting. Use a line only when the x values have meaningful order; connecting unrelated categories suggests a continuity that is not there.
Pillow opens common image formats and can resize, crop, rotate, and draw. Keep the original file and save transformed output under a new name until you have checked the result. Resizing changes pixel dimensions, but enlarging a small image cannot invent detail that was never captured. For text and logos, a vector source often scales more cleanly than a raster image.
Both charts and images need visual verification. A saved file can be technically valid but unreadable on a narrow screen, missing a legend, or cropped at the wrong coordinates. Check the exported artifact at the size a real reader will see. When charts convey essential information, provide a textual summary of the key values as well.
Read it line by line.
import matplotlib.pyplot as plt
weeks = [1, 2, 3]
completed = [4, 7, 6]
fig, ax = plt.subplots()
ax.plot(weeks, completed, marker='o')
ax.set(xlabel='Week', ylabel='Tasks completed')
fig.savefig('weekly-tasks.png', dpi=150)The x values are ordered weeks and the y values are task counts. plot draws a line with visible markers. set names both axes, and savefig writes a PNG. The example depends on the optional matplotlib package. The saved picture should preserve readable labels, margins, and the relationship between each week and count.
See the rule again.
from PIL import Image
image = Image.new('RGB', (200, 100), color='navy')
image.save('banner.png')
print(image.size)Pillow creates a 200-by-100 pixel RGB image and writes it as PNG; the printed size is (200, 100). Add drawing or text only after you know the coordinate system and output size.
A mistake to avoid.
Do not crop or overwrite the only copy of an image during exploration. Coordinate mistakes are easy to make, and a successful save does not guarantee the result shows the intended subject.