Thangam
Thangam

Reputation: 169

using more than one linestyle in the same trend line with matplotlib

I want to plot a line using the bold linestyle='k-' and after a certain value on the axes, I want the same line as dashed ('k--') or vice-versa. I want to show the dashed part as an extension to the bold line. One way to do this is to treat them as two individual plots and use different linestyles. I have attached the figure of an example. Just wondering if there was any other way to do this! enter image description here

Upvotes: 0

Views: 861

Answers (1)

Srivatsan
Srivatsan

Reputation: 9363

Yes it can be done. Following the suggestion given by @tom, one such example is:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(1,2,10)
y = np.linspace(1,2,10)

plt.plot(x[:4],y[:4],'-ko',x[3:],y[3:],'--ko')
plt.show()

This produces a plot: enter image description here

Upvotes: 1

Related Questions