Only 10 questions are needed to easily master Matplotlib graphics processing | Python skill tree

Hope Xiaohui 2021-10-29 03:00:53
questions needed easily master matplotlib

0. Preface

Matplotlib yes Python Drawing library of , It offers a complete set and matlab Similar orders API, It can generate exquisite graphics of publishing quality level ,Matplotlib Make drawing very simple , We'll pass 10 Avenue Python Programming questions to master the use Matplotlib Library for graphic drawing !

1. The first 1 topic : Drawing of curve

Knowledge point description : Draw a curve .
Problem description : Draw functions in the same picture y = x 2 y=x^2 y=x2, y = l o g e x y=log_ex y=logex as well as y = s i n ( x ) y=sin(x) y=sin(x), Please choose the correct answer from the following options :
A.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0.1, 2 * np.pi, 100)
y_1 = np.square(x)
y_2 = np.log(x)
y_3 = np.sin(x)
fig = plt.figure()
plt.plot(x,y_1)
fig = plt.figure()
plt.plot(x,y_2)
fig = plt.figure()
plt.plot(x,y_3)
plt.show()

B.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0.1, 2 * np.pi, 100)
y_1 = np.square(x)
y_2 = np.log(x)
y_3 = np.sin(x)
fig = plt.figure()
plt.plot(x,y_1)
plt.plot(x,y_2)
plt.plot(x,y_3)
plt.show()

C.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0.1, 2 * np.pi, 100)
y_1 = np.square(x)
y_2 = np.log(x)
y_3 = np.sin(x)
plt.plot(x,y_1, y_2, y_3)
plt.show()

D.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0.1, 2 * np.pi, 100)
y_1 = np.square(x)
y_2 = np.log(x)
y_3 = np.sin(x)
fig = plt.figure()
plt.plot(x,y_1, y_2, y_3)
plt.show()

right key : B

2. The first 2 topic : The drawing of scatter diagram

Knowledge point description : Draw a scatter plot .
Problem description : Draw function y = s i n ( x ) y=sin(x) y=sin(x) The points on the , Please choose the correct answer from the following options :
A.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0.1, 2 * np.pi, 50)
y = np.sin(x)
fig = plt.figure()
plt.plot(x, y)
plt.show()

B.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0.1, 2 * np.pi, 50)
y = np.sin(x)
fig = plt.figure()
plt.barh(x, y)
plt.show()

C.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0.1, 2 * np.pi, 50)
y = np.sin(x)
fig = plt.figure()
plt.bar(x, y)
plt.show()

D.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0.1, 2 * np.pi, 50)
y = np.sin(x)
fig = plt.figure()
plt.scatter(x, y)
plt.show()

right key : D

3. The first 3 topic : Drawing a bar chart

Knowledge point description : Draw a bar graph .
Problem description : Draw multiple sets of bar charts , Compare the sales volume of the corresponding quarter in different years , Please choose the right one from the following :
A.

import numpy as np
import matplotlib.pyplot as plt
data = [[10., 20., 30., 20.],[40., 25., 53., 18.],[6., 22., 52., 19.]]
x = np.arange(4)
colors = ['r', 'g', 'b']
for i in range(len(data)):
plt.bar(x + i * 0.25, data[:i], color = colors[i], width = 0.25)
plt.show()

B.

import numpy as np
import matplotlib.pyplot as plt
data = [[10., 20., 30., 20.],[40., 25., 53., 18.],[6., 22., 52., 19.]]
x = np.arange(4)
colors = ['r', 'g', 'b']
for i in range(len(data)):
plt.plot(x + i * 0.25, data[:i], color = colors[i], width = 0.25)
plt.show()

C.

import numpy as np
import matplotlib.pyplot as plt
data = [[10., 20., 30., 20.],[40., 25., 53., 18.],[6., 22., 52., 19.]]
x = np.arange(4)
colors = ['r', 'g', 'b']
for i in range(len(data)):
plt.bar(x + i * 0.25, data[i], color = colors[i], width = 0.25)
plt.show()

D.

import numpy as np
import matplotlib.pyplot as plt
data = [[10., 20., 30., 20.],[40., 25., 53., 18.],[6., 22., 52., 19.]]
x = np.arange(4)
colors = ['r', 'g', 'b']
for i in range(len(data)):
plt.plot(x + i * 0.25, data[i], color = colors[i], width = 0.25)
plt.show()

right key : C

4. The first 4 topic : The drawing of pie chart

Knowledge point description : Use a pie chart to compare the relative relationship between quantities .
Problem description : Draw the pie chart , Comparison list [10, 15, 30, 20] The relative relationship between quantities , Please choose the right one from the following :
A.

import matplotlib.pyplot as plt
data = [10, 15, 30, 20]
sum_data = sum(data)
plt.pie(data / sum_data)
plt.show()

B.

import matplotlib.pyplot as plt
data = [10, 15, 30, 20]
plt.pie(sum(data))
plt.show()

C.

import matplotlib.pyplot as plt
data = [10, 15, 30, 20]
plt.pie(range(len(data)), data)
plt.show()

D.

import matplotlib.pyplot as plt
data = [10, 15, 30, 20]
plt.pie(data)
plt.show()

right key : D

5. The first 5 topic : Histogram drawing

Knowledge point description : A histogram is used to represent the probability distribution .
Problem description : Draw the histogram according to the constructed array , Please choose the correct answer from the following options :
A.

import numpy as np
import matplotlib.pyplot as plt
x = np.random.randn(1024)
plt.hist(x, bins = 20)
plt.show()

B.

import numpy as np
import matplotlib.pyplot as plt
x = np.random.randn(1024)
plt.hist(x, bins=x.shape)
plt.show()

C.

import numpy as np
import matplotlib.pyplot as plt
x = np.random.randn(1024)
plt.hist(x.shape, x)
plt.show()

D.

import numpy as np
import matplotlib.pyplot as plt
x = np.random.randn(1024)
plt.hist(x, x.shape)
plt.show()

right key : A

6. The first 6 topic : Add the title

Knowledge point description : Add a title to the drawing .
Problem description : Add a Chinese title to the drawing , Please choose the correct answer from the following options :
A.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-4, 4, 10005)
y = 5 * (x + 4.2) * (x + 4.) * (x - 2.5)
plt.title(' curve ')
plt.plot(x, y, c = 'm')
plt.show()

B.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-4, 4, 10005)
y = 5 * (x + 4.2) * (x + 4.) * (x - 2.5)
plt.title(' curve ')
plt.plot(x, y, c = 'm')
plt.rcParams['font.sans-serif'] = ['SimSun']
plt.show()

C.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-4, 4, 10005)
y = 5 * (x + 4.2) * (x + 4.) * (x - 2.5)
plt.plot(x, y, c = 'm', title=' curve ')
plt.show()

D.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-4, 4, 10005)
y = 5 * (x + 4.2) * (x + 4.) * (x - 2.5)
plt.plot(x, y, c = 'm', title=' curve ')
plt.rcParams['font.sans-serif'] = ['SimSun']
plt.show()

right key : B

7. The first 7 topic : Label the axes

Knowledge point description : Add appropriate description labels for the coordinate axes of the drawing to help users understand the meaning of the drawing .
Problem description : A function is known to describe accelerated motion , Please draw a graph to show the relationship between time and distance :
A.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 8, 1000)
y = 2.0 * x + 0.5 * 5 * x ** 2
plt.xtitle('Time')
plt.ytitle('distance')
plt.plot(x, y, c = 'c')
plt.show()

B.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 8, 1000)
y = 2.0 * x + 0.5 * 5 * x ** 2
plt.plot(x, y, c = 'c', xlabel = 'Time', ylable = 'distance')
plt.show()

C.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 8, 1000)
y = 2.0 * x + 0.5 * 5 * x ** 2
plt.plot(x, y, c = 'c', xtitle = 'Time', ytitle = 'distance')
plt.show()

D.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 8, 1000)
y = 2.0 * x + 0.5 * 5 * x ** 2
plt.xlabel('Time')
plt.ylabel('distance')
plt.plot(x, y, c = 'c')
plt.show()

right key :D

8. The first 8 topic : Add a text description to the drawing

Knowledge point description : Add description text to the drawing , Highlight the importance of points or lines in the diagram .
Problem description : Use text to explicitly mark the midpoint of the function image , Please choose the correct answer from the following options :
A.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 8, 1000)
y = 2.0 * x + 0.5 * 5 * x ** 2
x_mid = x[0]
y_mid = y[0]
plt.scatter(x_mid, y_mid)
plt.text(x_mid, y_mid, 'mid')
plt.plot(x, y, c = 'c')
plt.show()

B.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 8, 1000)
y = 2.0 * x + 0.5 * 5 * x ** 2
x_mid = (x[-1] - x[0]) / 2
y_mid = 2.0 * ((x[-1] - x[0]) / 2) + 0.5 * 5 * ((x[-1] - x[0]) / 2) ** 2
plt.scatter(x_mid, y_mid)
plt.text('mid')
plt.plot(x, y, c = 'c')
plt.show()

C.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 8, 1000)
y = 2.0 * x + 0.5 * 5 * x ** 2
x_mid = x[-1]
y_mid = y[-1]
plt.scatter(x_mid, y_mid)
plt.text(x_mid, y_mid, 'mid')
plt.plot(x, y, c = 'c')
plt.show()

D.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 8, 1000)
y = 2.0 * x + 0.5 * 5 * x ** 2
x_mid = (x[-1] - x[0]) / 2
y_mid = 2.0 * ((x[-1] - x[0]) / 2) + 0.5 * 5 * ((x[-1] - x[0]) / 2) ** 2
plt.scatter(x_mid, y_mid)
plt.text(x_mid, y_mid, 'mid')
plt.plot(x, y, c = 'c')
plt.show()

right key :D

9. The first 9 topic : Add arrows to the drawing

Knowledge point description : Use arrows to indicate specific parts of the drawing .
Problem description : Use arrows to explicitly mark the midpoint of the function image , Please choose the correct answer from the following options :
A.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 8, 1000)
y = 2.0 * x + 0.5 * 5 * x ** 2
x_mid = (x[-1] - x[0]) / 2
y_mid = 2.0 * ((x[-1] - x[0]) / 2) + 0.5 * 5 * ((x[-1] - x[0]) / 2) ** 2
plt.annotate('mid',
ha = 'center', va = 'bottom',
xytext = (5, 30.),
xy = (x_mid, y_mid),
arrowprops = {
 'facecolor' : 'black', 'shrink' : 0.05 })
plt.plot(x, y, c = 'c')
plt.show()

B.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 8, 1000)
y = 2.0 * x + 0.5 * 5 * x ** 2
x_mid = (x[-1] - x[0]) / 2
y_mid = 2.0 * ((x[-1] - x[0]) / 2) + 0.5 * 5 * ((x[-1] - x[0]) / 2) ** 2
plt.annotate('mid',
ha = 'center', va = 'bottom',
xytext = (5, 30.),
x = x_mid,
y = y_mid,
arrowprops = {
 'facecolor' : 'black', 'shrink' : 0.05 })
plt.plot(x, y, c = 'c')
plt.show()

C.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 8, 1000)
y = 2.0 * x + 0.5 * 5 * x ** 2
x_mid = (x[-1] - x[0]) / 2
y_mid = 2.0 * ((x[-1] - x[0]) / 2) + 0.5 * 5 * ((x[-1] - x[0]) / 2) ** 2
plt.annotate('mid',
ha = 'center', va = 'bottom',
xtext = 5,
ytext = 30.,
xy = (x_mid, y_mid),
arrowprops = {
 'facecolor' : 'black', 'shrink' : 0.05 })
plt.plot(x, y, c = 'c')
plt.show()

D.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 8, 1000)
y = 2.0 * x + 0.5 * 5 * x ** 2
x_mid = (x[-1] - x[0]) / 2
y_mid = 2.0 * ((x[-1] - x[0]) / 2) + 0.5 * 5 * ((x[-1] - x[0]) / 2) ** 2
plt.annotate('mid',
ha = 'center', va = 'bottom',
xtext = 5,
ytext = 30.,
xy = (x_mid, y_mid),
arrowprops = {
 'facecolor' : 'black', 'shrink' : 0.05 })
plt.plot(x, y, c = 'c')
plt.show()

right key :A

10. The first 10 topic : Add a legend to the drawing

Knowledge point description : Add corresponding legends for curves and points in the drawing , To make an accurate distinction .
Problem description : A graph contains multiple curves and scatter points , Add legends to them , Please choose the correct answer from the following options :
A.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 6, 1024)
data = np.random.standard_normal((150, 2))
y_1 = np.sin(x)
y_2 = np.cos(x)
plt.plot(x, y_1, c = 'm', lw = 3., text = 'sin(x)')
plt.plot(x, y_2, c = 'c', lw = 3., ls = '--', text = 'cos(x)')
plt.scatter(data[:,0], data[:, 1], c = 'y', text = 'random')
plt.legend()
plt.show()

B.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 6, 1024)
data = np.random.standard_normal((150, 2))
print(data.size)
y_1 = np.sin(x)
y_2 = np.cos(x)
plt.plot(x, y_1, c = 'm', lw = 3., title = 'sin(x)')
plt.plot(x, y_2, c = 'c', lw = 3., ls = '--', title = 'cos(x)')
plt.scatter(data[:,0], data[:,1], c = 'y', title = 'random')
plt.legend()
plt.show()

C.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 6, 1024)
data = np.random.standard_normal((150, 2))
y_1 = np.sin(x)
y_2 = np.cos(x)
plt.plot(x, y_1, c = 'm', lw = 3., label = 'sin(x)')
plt.plot(x, y_2, c = 'c', lw = 3., ls = '--', label = 'cos(x)')
plt.scatter(data[:, 0], data[:, 1], c = 'y', label = 'random')
plt.legend()
plt.show()

D.

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 6, 1024)
data = np.random.standard_normal((150, 2))
y_1 = np.sin(x)
y_2 = np.cos(x)
plt.plot(x, y_1, c = 'm', lw = 3., legend = 'sin(x)')
plt.plot(x, y_2, c = 'c', lw = 3., ls = '--', legend = 'cos(x)')
plt.scatter(data[:, 0], data[:, 1], c = 'y', legend = 'random')
plt.legend()
plt.show()

right key :C

Question code address

https://codechina.csdn.net/LOVEmy134611/python_problem

版权声明
本文为[Hope Xiaohui]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/10/20211013145815502j.html

  1. 预备知识-python核心用法常用数据分析库(下)
  2. python 文件排版,怎么控制写入在对应文件的位置(要写吐了,真是服了)
  3. Preliminary Knowledge - Python Core use Common Data Analysis Library (ⅰ)
  4. Typographie de fichiers Python, comment contrôler l'écriture à l'emplacement du fichier correspondant (pour écrire et vomir, vraiment pris)
  5. python:例题求解,不知道怎么等输入完所有数字后再输出
  6. 用python来实现:根据实际查询结果补充完整数据
  7. Mise en œuvre en python: compléter les données complètes en fonction des résultats réels de la requête
  8. python对excel进行分组但不进行聚合统计操作,且输出到不同的表格中?
  9. Python regroupe Excel, mais n'effectue pas de statistiques agrégées, et l'affiche dans différents tableaux.
  10. python如何提交,不要用太复杂的函数
  11. Comment soumettre Python sans utiliser de fonctions trop complexes
  12. Python,数据文件操作问题,想要代码
  13. python 提取多个字符串中的多个字段
  14. python 读入用户输入的一组正整数,到-1结束
  15. Python lit un ensemble d'entiers positifs entrés par l'utilisateur, se terminant par - 1
  16. 测试逐飞的MM32F3277 MicroPython开发板的基本功能
  17. Python timer reference
  18. 关于#python#的问题:python3队列维护
  19. Developing Hongmeng equipment program using python (3-prototype of security system)
  20. Questions sur # # Python #: maintenance de la file d'attente Python 3
  21. 怎么用Python打印数字三角
  22. 怎麼用Python打印數字三角
  23. Comment imprimer un triangle numérique en python
  24. Tester la fonctionnalité de base du tableau de développement microspython mm32f3277 Flying - by - flying
  25. Python extrait plusieurs champs de plusieurs chaînes
  26. Pandas核心用法
  27. Utilisation centrale de pandas
  28. Python, problème de fonctionnement du fichier de données, Code désiré
  29. 【78技术人社群~Python分部】,就在今天成立 →
  30. 社区共读《Python编程从入门到实践》第一天阅读建议
  31. La communauté lit les recommandations de lecture pour la première journée de la programmation Python de l'introduction à la pratique
  32. [78 Communauté des technologues ~ Division Python], fondée aujourd'hui →
  33. Pandas核心用法
  34. 您好,请问您的python按钮开了线程处理还卡ui的问题解决了吗
  35. Python: résolution d'exemples, je ne sais pas comment attendre que tous les chiffres soient entrés avant de sortir
  36. Bonjour, puis - je vous demander si votre bouton Python est activé pour le traitement du thread et le retour de l'interface utilisateur de la carte a été résolu?
  37. Utilisation centrale de pandas
  38. Python technique 2: advanced usage of function parameters
  39. OpenCV-Python实战(14)——人脸检测详解(仅需6行代码学会4种人脸检测方法)
  40. OpenCV-Python實戰(14)——人臉檢測詳解(僅需6行代碼學會4種人臉檢測方法)
  41. OpenCV - Python Real play (14) - face detection details (six lignes de code seulement pour apprendre 4 méthodes de détection de visage)
  42. 你好,python开发mes系统,能分享下吗,我最近也想搞这方面的
  43. 你好,python開發mes系統,能分享下嗎,我最近也想搞這方面的
  44. Bonjour, Python a développé mon système, pouvez - vous le partager?
  45. Introduction to tuples in Python
  46. Introduction to strings in python (Part 2)
  47. Introduction to strings in python (Part 1)
  48. python关于 if 的简单操作时,输出结果不是预期所要的结果 的问题
  49. python關於 if 的簡單操作時,輸出結果不是預期所要的結果 的問題
  50. Lorsque Python fonctionne simplement sur if, la sortie n'est pas le résultat attendu
  51. Python中字典问题请求解惑
  52. Python中字典問題請求解惑
  53. Demande de résolution de problèmes de dictionnaire en python
  54. Python中字典问题请求解惑
  55. Python technique 2: advanced usage of function parameters
  56. Demande de résolution de problèmes de dictionnaire en python
  57. Preliminary Knowledge - Python Core use Common Data Analysis Library (ⅱ)
  58. 关于python的代码问题,终端打印为什么会起飞
  59. En ce qui concerne les problèmes de code Python, pourquoi l'impression du terminal décolle - t - elle?
  60. Python中种子seed的运用问题