2015-10-26 3 views

ответ

7

Вы можете создать гораздо больше, чем эти четыре типа, используя аргумент dashes, чтобы указать пользовательские стили стилей. Например:

import numpy as np 
import matplotlib.pyplot as plt 

x = np.linspace(0, 10) 
y = np.sin(x) 
plt.plot(x, y, dashes=[10, 5, 20, 5], linewidth=2, color='black') 

enter image description here

dashes аргумент представляет собой список целых чисел, которые указывают размер штрихов и промежутков в точках: в приведенном выше примере есть 10-точка тире, 5-балльной пробел, 20-точечный тире и другое 5-точечное пространство, после чего последовательность повторяется.

2

Вот еще один пример, который вы можете использовать, чтобы опробовать различные стили на заказ линии (как элементы в списке «dashList»), и адаптировать, если вы хотите использовать несколько различных пользовательские стили линий в ваших участках:

import matplotlib.pyplot as plt 

dashList = [(5,2),(2,5),(4,10),(3,3,2,2),(5,2,20,2)] 
# List of Dash styles, each as integers in the format: (first line length, first space length, second line length, second space length...) 

# set up the axes to look nice: 
frame1 = plt.gca() 
frame1.axes.xaxis.set_ticklabels([]) # hide x axis numbers 
plt.xlim(0,6) # set x and y axis extents 
plt.ylim(-0.5,len(dashList)-0.5) 
plt.ylabel("dashList element") # add a label to the y axis 

for n in range(0,len(dashList)): 
    plt.plot([0.5,4],[n,n], color = 'black', linestyle='--', dashes=dashList[n]) # plot a horizontal line using each custom line style 
    # NB plot.plt draws a line between the following points: ([x0,x1],[y0,y1]) 
    plt.text(4.5,n,dashList[n]) # ...and show the numbers used to generate each custom linestyle 
plt.show() 

enter image description here

Смежные вопросы