python - generate scatter chart and save it to png file using matplotlib pyplot

Python
[Edit]
+
0
-
0

Python - generate scatter chart and save it to PNG file using Matplotlib Pyplot

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
import matplotlib.pyplot as plt # === Chart data preparation === x = [ [-4. ], [-3.11111111], [-2.22222222], [-1.33333333], [-0.44444444], [ 0.44444444], [ 1.33333333], [ 2.22222222], [ 3.11111111], [ 4. ] ] y = [ [16. ], [ 9.67901235], [ 4.9382716 ], [ 1.77777778], [ 0.19753086], [ 0.19753086], [ 1.77777778], [ 4.9382716 ], [ 9.67901235], [16. ] ] # === Scatter chart generating === plt.figure(figsize=(8, 6)) plt.scatter(x, y, c='blue', alpha=0.5) plt.title("Scatter chart", fontsize=16) plt.xlabel("x", fontsize=14) plt.ylabel("y", fontsize=14) plt.grid(True) plt.savefig("scatter_chart.png") plt.close() # Notes: # 1) to install Matplotlib Pyplot globally use `pip install --upgrade matplotlib` command. # 2) to install Matplotlib Pyplot locally use `./.venv/bin/pip install --upgrade matplotlib` command. # References: # 1) https://matplotlib.org/stable/install/index.html