#!/usr/bin/env python
#-*- coding: utf-8 -*-
import math
import random
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpathes
from wrTXT import ReadDataTxt
def test_01():
x = np.linspace(0, 10, 40)
plt.figure(1) #Create artboard1
plt.subplot(221) #Enter area 221 to make a map
# (x, (x), 'g', label="sin(x)", linewidth = 2.5 ) # green linewidth 2.5
plt.plot(x, np.sin(x), color='#2DCCD3', label="sin(x)", linewidth = 2.5, marker='^', linestyle='--') # green linewidth 2.5
plt.legend(loc="upper right") # Set label as position, display in the upper right corner
plt.axhline(y = 0.8, ls='--', c='r', linewidth = 2.5) #Draw horizontal reference lines parallel to x-axis y=0.8
plt.ylim(-1.5, 1.5)
# Draw the reference area perpendicular to the x-axis x<4 and x>6, and the reference area perpendicular to the y-axis y<0.2 and y>-0.2
plt.axvspan(xmin=4, xmax=6, facecolor='r', alpha=0.3) # Vertical x-axis
plt.axhspan(ymin=-0.2, ymax=0.2, facecolor='y', alpha=0.3); # Vertical y-axis
# Add comment text sin(x)
plt.text(8.0, 1.5, 'sin(x)', weight='bold', color='g', fontsize=15) # 8.0, 1.5 is x, y
# Use arrows to mark the first peak
plt.annotate('maximum',xy=(np.pi/2, 1),xytext=(np.pi/2+1, 1),
weight='bold',
color='r',
arrowprops=dict(arrowstyle='->', connectionstyle='arc3', color='r'), fontsize=15)
plt.title('BUAA 01', fontsize=20) # Specify the title of the graph in area 221
plt.axis('equal') # Specify the x and y ratio of the 221 area to one
plt.xlabel('variable x', fontsize=15) # Specify the x-axis title, and set the font size
plt.ylabel('value y', fontsize=15) # Specify the y-axis title, and set the font size
plt.grid() # Show mesh
plt.subplot(222) #Enter area 222 to make a map
plt.plot(x, np.sin(x), 'r-o', label="sin x") # red -o
plt.legend(loc="upper right") # Set label as position, display in the upper right corner
plt.title('BUAA 02') # Specify the title of the graph in the 111 area
plt.axis('equal') # Specify the x and y ratio of 111 areas to one
plt.grid()
plt.subplot(223) #Enter area 223 to make a map
plt.scatter(x, np.sin(x))
plt.title('BUAA 03') # Specify the title of the graph in the 111 area
plt.axis('equal') # Specify the x and y ratio of 111 areas to one
plt.grid()
plt.subplot(224) #Enter area 224 to make a map
plt.plot(x, np.sin(x), 'g--', linewidth = 2.5) # green linewidth 2.5
plt.title('BUAA 04') # Specify the title of the graph in the 111 area
plt.axis('equal') # Specify the x and y ratio of 111 areas to one
plt.grid()
plt.show()
# Display a set of 4-dimensional data using the area and color of the pie chart
def test_02():
plt.figure(1)
plt.subplot(111)
rng = np.random.RandomState(0)
x = rng.randn(100)
y = rng.randn(100)
colors = rng.rand(100)
sizes = 1000 * rng.rand(100)
plt.scatter(x, y, c=colors, s=sizes, alpha=0.3, cmap='viridis')
plt.colorbar(); # Display color level
plt.show()
# Bar chart
def test_03():
plt.figure(1)
plt.subplot(111)
x = [1,2,3,4,5,6,7,8]
y = [3,1,4,5,8,9,7,2]
label = ['A','B','C','D','E','F','G','H']
plt.bar(x, y, tick_label = label)
plt.show()
if __name__ == "__main__":
test_01()