python中的极坐标图

2024-05-15 03:16:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我想画一个1/t的极坐标图。到目前为止我所拥有的是下面的(这可能是错误的)。我怎样才能完成这件事或使它成功?

from pylab import *
import matplotlib.pyplot as plt

theta = arange(0, 6 * pi, 0.01)


def f(theta):
    return 1 / theta

Polar Plot in Mathematica


Tags: fromimportreturnmatplotlibdefas错误pi
4条回答

我已经有一段时间没有深入研究Java了,但是您是否已经尝试过先做这个了

board[0][0] = new hexagon(); // or whatever its constructor is

要扩展kwatford所说的内容,在java中初始化数组时,如果数组类型是对象,则会得到null。如果您有一个原始数组,例如一个双精度数组,那么您将以0作为数组中每个元素的条目开始

在夸特福德。第7行所做的就是告诉java在二维数组中为n*n个六边形对象创建空间

您仍然需要为这些六边形中的每一个调用new

基本上,您需要将第7行替换为以下内容:

board = new Hexagon[n][n];
for(int i=0; i<n; i++)
    for(int j=0; j<n; j++)
        board[i][j] = new Hexagon();

简短回答:

正如夸特福德所说,你需要做的是:

board[0][0] = new hexagon(); // or whatever its constructor is

详细解释:

只是为了进一步扩大。你的二维阵列是;指针数组(或Java中的引用)。这是在调用board = new hexagon[n][n];之后立即显示的数组的一行:

    0      1      2      3      4      5       // column index, row index = 0
-------------------------------------------
|   |   |   |   |   |   |      |      |      |    // value
--- | ----- | ----- | ---------------------
    |       |       |      ...
    |       |       |
    |       |       |
    |       |       |
    |       |       v
    |       |       Null
    |       v       
    |       Null
    v
    Null (This means that it points to nothing)

你试过:

board[0][0].value = 'R';

与此相同:

null.value = 'R';

您已经使用以下行初始化了数组:

board = new Hexagon[n][n];

但是您仍然需要初始化数组中的元素。这将初始化前三个:

board[0][0] = new hexagon(); // or whatever its constructor is
board[1][0] = new hexagon(); // or whatever its constructor is
board[2][0] = new hexagon(); // or whatever its constructor is

这将导致一个如下所示的数组:

    0      1      2      3      4      5       // column index, row index = 0
-------------------------------------------
|   |   |   |   |   |   |      |      |      |    // value
--- | ----- | ----- | ---------------------
    |       |       |
    |       |       |
    |       |       |
    |       |       |
    |       |       v
    |       |       An instance of type Hexigoon (what you get when you type new Hexigon)
    |       v       
    |       An instance of type Hexigon (what you get when you type new Hexigon)
    v
    An instance of type Hexigon (what you get when you type new Hexigon)

我记得两年前就因为这个问题把头撞在桌子上。我爱stackoverflow

相关问题 更多 >

    热门问题