简体   繁体   English

图形未显示在Python图中

[英]Graph not showing in Python plot

I have the following code in Python for plotting a simple graph: 我在Python中有以下代码用于绘制简单图形:

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. 如果我使用plt.scatter()代替,它将正常绘制点。 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. 我正在阅读,这可能是后端的问题,但是我的matlibrc文件夹为空,并且那里没有任何配置文件。 Anyone with similar experience? 有类似经验的人吗? Any ideas of the problem? 对这个问题有什么想法吗?

The problem is that each 'line' only comprises one point at (i,2i). 问题在于,每条“线”仅在(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. 例如,可以通过将选项marker='o'plt.plot(...)命令来绘制点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM