SW/Python
[matplotlib] 2D/3D Plot tutorial, mpl_toolkits import mplot3d
Fun with x
2024. 1. 31. 21:06
Create Data
import pandas as pd
import numpy as np
import math as m
a=[i for i in range(1,82)]
b=[i*j for i in range(1,10) for j in range(1,10)]
c=[n**2 if n%2 == 0 else n**3 for n in range(1,82)]
df = pd.DataFrame({"a":a, "b":b, "c":c})
2D Plot
import matplotlib.pyplot as plt
plt.title('?Title?')
plt.plot(a,b,marker='o', linestyle='--',color='b',linewidth=1,label='b_plot')
plt.scatter(a,b,color='b',s=5,label='b_scatter')
plt.xlabel('a')
plt.ylabel('b')
plt.annotate('local max', xy=(50, 50), xytext=(50, 50),arrowprops=dict(facecolor='r', shrink=0.05))
plt.grid(True)
plt.legend(loc='upper right')
ax.view_init(60, 35) #보는각도
plt.show()
3D Plot
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
fig = plt.figure()
ax = plt.axes(projection='3d')
plt.title('?Title?')
ax.plot(a,b,c,marker='o', linestyle='--',color='b',linewidth=1,label='b_plot')
ax.scatter(a,b,color='b',s=5,label='b_scatter')
ax.set_xlabel('a')
ax.set_ylabel('a')
ax.set_zlabel('c')
plt.annotate('local max', xy=(50, 50), xytext=(50, 50),arrowprops=dict(facecolor='r', shrink=0.05))
plt.grid(True)
plt.legend(loc='upper right')
ax.view_init(60, 35) #보는각도
plt.show()