1. Demand
During the electromagnetic design of the motor, some parameters need to be optimized, so the data is derived from the electromagnetic simulation software Maxwell, and some of the data are shown in the figure below.
However, the influence of parameters cannot be seen directly, so it is adjusted to matrix form, as shown in the figure below.
In this way, although the influence of input parameters (current and diameter) on output parameters (torque) can be seen intuitively, it is not beautiful enough. Therefore, it is hoped to produce a three-dimensional diagram.
So our demand is to draw the above table into a three-dimensional diagram. Matlab or Python can draw three-dimensional drawings. Since this computer can't bring MATLAB, choose a lighter and free Python to draw.
2. Effect
3. Source code
# -*- coding: utf-8 -*- """ Created on Wed Nov 4 11:50:31 2021 @author: 29235 """ import matplotlib.pyplot as plt import pandas as pd from matplotlib import pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = Axes3D(fig) X = np.array([40, 40.5, 41, 41.5, 42, 42.5, 43, 43.5, 44, 44.5, 45, 45.5, 46]) Y = np.array([73, 73.4, 73.8, 74.2, 74.6, 75]) X, Y = np.meshgrid(X, Y) print("X Dimension information",X.shape) print("Y Dimension information",Y.shape) Z = np.array([[6.589055889,6.64902114,6.708506801,6.76873195,6.826929116,6.883863945,6.941234139,7.000980041,7.054255481,7.109803791,7.164581639,7.218312404,7.270706248 ], [6.791371118,6.852543525,6.913251843,6.973519432,7.033344309,7.092707208,7.151614187,7.210021177,7.267848299,7.324956649,7.381181255,7.436250947,7.489788889 ], [6.831692483,6.89286339,6.953606738,7.013941807,7.073861088,7.133397721,7.192511521,7.251186927,7.309458728,7.367340603,7.424484379,7.481372044,7.537841682 ], [7.086868085,7.149849934,7.212869543,7.275419973,7.337549343,7.399451263,7.461001477,7.522183123,7.582986224,7.643290063,7.703127756,7.762594775,7.821019196 ], [7.294926321,7.363130314,7.430014234,7.485656198,7.539103262,7.603323023,7.666993121,7.73028388,7.792974692,7.855100171,7.916647003,7.977528019,8.037752676 ], [7.694961389,7.766138728,7.83685522,7.907105954,7.976906299,8.046261641,8.114924107,8.183130388,8.250939779,8.318071108,8.384670594,8.450760983,8.516177871 ], ]) print("Z Axis data dimension",Z.shape) ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='rainbow') ax.set_xlabel('I(A)', color='b') ax.set_ylabel('D(mm)', color='g') ax.set_zlabel('T(Nm)', color='r') plt.draw() plt.show()
I wrote this code in spyder, because when running the code with spyder, the generated pictures will be drawn with spyder's Plots by default, so the resulting pictures are static and cannot be rotated.
It is said on the Internet that the picture viewer provided by matplotlib can rotate to view three-dimensional pictures, but I didn't find a way to draw without Plots in spyder.
So I thought of a way.
4. Special requirements (free rotation)
Open the command line and change the directory to the directory where the drawing code is located.
Activate the environment. (because I use the self built environment to process data, I need to activate the environment. If you use the default environment to draw, you don't need this step)
Enter the command python I_D_T_Data_Process.py
That is, run the. py file directly, which will call the graphics display provided by matplotlib. At this point, you can freely rotate the three-dimensional diagram.