Data Science Explorer

Matplotlib: Matplotlib Line 본문

Python

Matplotlib: Matplotlib Line

grace21110 2023. 11. 5. 10:30
반응형
  • Linestyle 

If you want to change the style of the line, you can use ls.

 

Example 

import  matplotlib.pyplot as plt
import numpy as np 
ypoints = np.array ([2,6,7,0]) 

plt.plot(ypoints, ls = 'dotted')
plt.show()

 

  • Shorter Syntax 
  • linestyle can be written as ls.
  • dotted can be written as :.
  • dashed can be written as --.

 

  • Line Styles 
Style  Or
'solid' (default) '-'
'dotted' ':'
'dashed' '--'
'dashdot' '-.'
   
'None' '' or ' '

 

 

  • Line Color 

You can use argument c to set the color of the line. 

 

Example 

import matplotlib.pyplot as plt 
import numpy as np 

ypoints = np.array ([2,3,6,9]) 

plt.plot(ypoints, color = 'r') 

plt.show()

 

Result 

 

  • Line Width 

We can also adjust the width of the line by using lw.

import matplotlib.pyplot as plt 
import numpy as np 

y =([3, 4, 5, 7]) 

plt.plot(y, lw = '20')
plt.show()

 

Result 

 

  • Multiple Lines 

You can plot as many lines as you like by simply adding more plt.plot() functions. 

import matplotlib.pyplot as plt 
import numpy as np 

y1 = np.array ([1, 3, 5, 9])
y2 = np.array([6, 2, 7, 11])

plt.plot(y1)
plt.plot(y2)

plt.show()

 

Result

'Python' 카테고리의 다른 글

Matplotlib Subplot  (0) 2023.11.07
Matplotlib: Matplotlib Adding Grid Lines  (0) 2023.11.06
Matplotlib: Matplotlib Labels and Title  (0) 2023.11.05
Matplotlib: Matplotlib Markers  (2) 2023.11.04
Matplotlib: Matplotlib Plotting  (0) 2023.11.04