python - Two point segment plot in matplotlib -


how can plot 2 point line segment plot shown in following figure enter image description here

the data below

x = [1,2,3,4,5,6]

y = [1.2,1.2,-2.1, -2.1, 4.1, -4.1] #these y values in pair such need solid line connect these equivalent values , dotted line between pair , next pair.

does achieve hoping?

import numpy np import matplotlib.pyplot plt  x = [1, 2, 3, 4, 5, 6] y = [1.2, 1.2, 2.1, 2.1, -4.1, -4.1]  plt.plot(x, y, 'm--')  pair_x_array = np.reshape(x, (-1, 2)) pair_y_array = np.reshape(y, (-1, 2)) i, pair_x in enumerate(pair_x_array):     pair_y = pair_y_array[i]     plt.plot(pair_x, pair_y, 'm', linewidth=3)  plt.show() 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -