3

My desired outcome is a graph that looks like this

ax.plot(df.x, df.y, 'b.-')

where a line is generated with a dot at every location there is a data point. But I also want specific colors like "lightsteelblue".

When I try plotting

ax.plot(df.x, df.y, color='lightsteelblue', ls='.-')

a value error comes up that '.-' is not supported with "ls". Any ideas on how to get around this?

Thanks for your time, -Bojan

1
  • 1
    can you provide a full reproducible code and a schematic of the expected output? Commented Mar 15, 2022 at 12:53

2 Answers 2

7

below code should work for you

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, np.random.randint(1, 7) , 10)
y = np.linspace(0, np.random.randint(7, 9), 10)

fig, ax = plt.subplots()

ax.plot(x, y, **{'color': 'lightsteelblue', 'marker': 'o'})

plt.show()

output

enter image description here

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

1 Comment

in addition markevery=n can limit the number of markers, one out of n.
4

The argument ls is short for linestyle, but you're trying to also pass it a marker style. But to pass a marker style you need to use the marker argument, e.g.

ax.plot(x, y, color='black', ls='-', marker='.')

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.