SoFunction
Updated on 2024-10-29

Sample code for Matplotlib to plot radar and 3D maps

1. Radar charts

Example of a program

'''1. Blank polar plots'''
import  as plt
 
()
()
 
'''2. Plot a polar point'''
import numpy as np
import  as plt
# polar coordinates (0.25*pi,20)
(0.25*, 20, 'ro', lw=2)  # 'ro' red dots #
(0,50)
()
 
'''3. Plotting multiple polar points'''
import numpy as np
import  as plt
theta = ([0.25,0.5,0.75,1,1.25,1.5,1.75,2])
r = [75,60,50,70,50,85,45,70]
(theta*, r, 'ro', lw=2)  # 'ro' red dots #
(0,100)
()
 
'''4. Linking polar points'''
import numpy as np
import  as plt
theta = ([0.25,0.5,0.75,1,1.25,1.5,1.75,2])
r = [75,60,50,70,50,85,45,70]
(theta*, r, 'ro-', lw=2)
(0,100)
()
 
'''5. Closed link polar points'''
import numpy as np
import  as plt
# Simply add a point at the end that coincides with the start point
theta = ([0.25,0.5,0.75,1,1.25,1.5,1.75,2,0.25])
r = [75,60,50,70,50,85,45,70, 75]
(theta*, r, 'ro-', lw=2)
(0,100)
()
 
'''6. Fill color'''
import numpy as np
import  as plt
# Simply add a point at the end that coincides with the start point
theta = ([0.25,0.5,0.75,1,1.25,1.5,1.75,2,0.25])
r = [75,60,50,70,50,85,45,70, 75]
(theta*, r, 'ro-', lw=2)
(theta*, r, facecolor='r', alpha=0.5) # Filling
(0,100)
()
 
'''7. Mapping the radar of achievement'''
import numpy as np
import  as plt
 
courses = ['C++', 'Python', 'Java', 'C', 'C#', 'Go', 'Matlab']
scores = [82,100,90,78,40,66,88]
 
datalength = len(scores)
angles = (0, 2*, datalength, endpoint=False)  # Mean polar coordinates
 
(scores[0])  # Add the first value at the end to make sure the curve is closed #
angles = (angles, angles[0])
 
(angles, scores, 'rv-', lw=2)
(angles*180/, courses, fontproperties='simhei')
(angles, scores, facecolor='r', alpha=0.4)

 

2. Three-dimensional drawing

Example of a program

'''1. Draw 3D curves and set the legend font size'''
import  as plt
import numpy as np
import matplotlib as mpl
import matplotlib.font_manager as fm
from mpl_toolkits.mplot3d import Axes3D # Indispensable
 
fig = ()
ax = (projection='3d')  # Set image properties
 
# Test data
theta = (-4 * , 4*, 100)
z = (-4,4,100) * 0.3
r = z**4 + 1
x = r*(theta)
y = r*(theta)
 
(x,y,z,'b^-', label='3D Test Curve')
# Set the legend font, font size
font = ('simhei')
[''] = 10
(prop=font)
 
()
 
'''2. draw a three-dimensional bar graph with each bar colored randomly'''
import numpy as np
import  as plt
import mpl_toolkits.mplot3d
 
x = (0,40,10)
y = (0,40,10)
z = 80*abs((x+y))
 
ax = (projection='3d')
 
for xx, yy, zz in zip(x,y,z):
  color = (3)
  ax.bar3d(xx, yy, 0, dx=1, dy=1, dz=zz, color=color)
 
ax.set_xlabel('X-axis', fontproperties='simhei')
ax.set_ylabel('Y-axis', fontproperties='simhei')
ax.set_zlabel('Z-axis', fontproperties='simhei')
 
()

This is the whole content of this article.