0

I have the following code in Python for plotting a simple graph:

import numpy as np
import matplotlib.pyplot as plt

for i in (2, 3, 4, 5, 6):
    plt.plot(i, 2*i, linewidth = 3, label='$n = {i}$'.format(i=i))
plt.legend(loc='upper left')
plt.show()

When I execute it shows the window with the legend, but not the graph line. If I use plt.scatter() instead it plots the points normally. I was reading that it maybe an issue of the backend, but my matlibrc folder is empty and I don't have any config file there. Anyone with similar experience? Any ideas of the problem?

1 Answer 1

1

The problem is that each 'line' only comprises one point at (i,2i). Using a line only, this does not result in anything. One can plot the point for example by adding the option marker='o' to the plt.plot(...) command.

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

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.