Search code examples
pythonmatplotlibstyleslineline-plot

Plot one line with multiple line styles


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


Solution

  • 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