SoFunction
Updated on 2025-03-02

Introduction to Python drawing learning tutorial

This article describes the basic method of drawing in Python. Share it for your reference, as follows:

Python: Draw charts using matplotlib

Python's method of drawing charts has a powerful class library matplotlib, which can produce high-quality 2D and 3D graphics. Record it first and learn it slowly later.

matplotlib download and API manual address:/projects/matplotlib/files/matplotlib/

Mathematics library numpy download and API manual address:/Download

Several drawing examples, from the API manual:

1. The simplest picture:

Code:

#!/usr/bin/env python
import  as plt
([10, 20, 30])
('tiems')
('numbers')
()

2. Pie chart:

Code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pylab import *
# make a square figure and axes
figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15,30,45, 10]
explode=(0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5})
savefig('D:\\')
show()

3. Use numpy library functions:

Code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import  as plt
t = (0.0, 1.01, 0.01)
s = (2*2**t)
(t, s*(-5*t), 'r')
(True)
#Save it as PDF format, or save it as PNG and other graphics formats('D:\\')
()

For more information about Python-related content, please check out the topic of this site:Summary of Python encoding operation skills》、《Summary of Python image operation skills》、《Python data structure and algorithm tutorial》、《Summary of Python Socket Programming Tips》、《Summary of Python function usage tips》、《Summary of Python string operation skills》、《Python introduction and advanced classic tutorials"and"Summary of Python file and directory operation skills

I hope this article will be helpful to everyone's Python programming.