1

The data:

x = 300, 300, 300, 300, 300

y = 1200, 900, 200, -600, -1371

I already plot with matplotlib using plt.plot(x, y, marker='s', linestyle='dotted') yet it just show one style.

Is it possible if I want to make the line plot with two different line styles, from (300,1200) to (200,300) with solid style and then the rest is dotted.

Please help. Thanks

1
  • You need to split the data and plot as separate lines Commented Sep 9, 2020 at 9:53

2 Answers 2

1

As I stated in the comments you will need to split up your data like so:

x_dotted = x[3:]
y_dotted = y[3:]

x_solid = x[:3]
y_solid = y[:3]

Then just call plt.plot with your desired parameters

Sign up to request clarification or add additional context in comments.

Comments

1

I think this answer is good for your question. I tried to modify it for line styles. For more information read about LineCollection.

import numpy as np
from matplotlib.collections import LineCollection
import matplotlib.pyplot as plt


x = np.array([300, 300, 300, 300, 300])
y = np.array([1200, 900, 200, -600, -1371])


points = np.array([x, y]).T.reshape(-1, 1, 2)


segments = np.concatenate([points[:3], points[-3:]], axis=1)
line_styles = [("dashed"),("solid")]

lc = LineCollection(segments, linestyles=line_styles, color='black')

fig,a = plt.subplots()
a.add_collection(lc)
a.set_xlim(0,500)
a.set_ylim(-1500,1500)
plt.show()

result

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.