Why does this render an empty plot?

Linde

I would like to know why this python code:

import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
x = np.arange(-3,3,100)
y = -(np.arctan(-1/x))
plt.ylim((-1.5,1.5))
plt.plot(x,y)
plt.show()

renders an empty plot, with the axes having my desired limits. Wolfram Alpha assures me that the function should be visible within these limits. I am completely lost here.

Thomas Lang

Your range contains only a single point x = [-3], hence you won't plot much. What you want is to create a linear space using

x = np.linspace(-3,3,100)

Then your function will be visible.

Edit: Explanation of the first sentence:

np.arange(start, stop, step)

This will create a range starting at start, stopping at stop (exclusive) and stepping by step. Thus you start with -3, the next value must be at stride -3 + 100 = 97, but this is not smaller than 3. Thus the range only contains the start number.

np.linspace(start, stop, number) instead will create a range in the interval [start,stop] divided equidistant in number partitions.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Why seaborn's pairplot does not plot the first plot?

分類Dev

Why does ValueMember override an empty DisplayMember

分類Dev

Why does setting an input value to undefined not empty it?

分類Dev

Why does -d return true on empty variable

分類Dev

Why does strcat not work with empty string in C?

分類Dev

Why does my empty SD-Card is not empty

分類Dev

Why does indexOf on an empty array does not return -1?

分類Dev

Why does this create an infinite render loop with React hooks?

分類Dev

Python saving empty plot

分類Dev

Matplotlib: Check for empty plot

分類Dev

Bokeh plot is empty

分類Dev

Why does play.libs.Json.toJson return an empty object?

分類Dev

Why does play.libs.Json.toJson return an empty object?

分類Dev

Why does Azure Application Gateway require an empty subnet

分類Dev

Why does MongoDB $size returns 1 for an empty sub-array?

分類Dev

Why does `a.is_a? Array && !a.empty?` raise NoMethodError?

分類Dev

Why does an empty string literal in a multidimensional array decay to a null pointer?

分類Dev

Why does useCallback with an empty dependency array not return the same function?

分類Dev

Why does writing empty std::istringstream.rdbuf() set failbit?

分類Dev

Why does my database gets empty on adding data to another database?

分類Dev

Why does crypto.subtle.digest return an empty Object

分類Dev

Why does console.log wrongly print an empty array?

分類Dev

Graphs, vertices, STL lists: Why does list come out empty?

分類Dev

Glyphicon does not render to the template

分類Dev

Image does not render with KineticJS

分類Dev

Why does stacked bar plot change when add facet in r ggplot2

分類Dev

Why does multiple inheritance increase the size of the object despite the bases being empty?

分類Dev

Why does a leading null value in an array cause string.Join() to return empty string?

分類Dev

Why does string.Join(" ", new object[] { null, "a", null, "b"}) retruns string.Empty?

Related 関連記事

  1. 1

    Why seaborn's pairplot does not plot the first plot?

  2. 2

    Why does ValueMember override an empty DisplayMember

  3. 3

    Why does setting an input value to undefined not empty it?

  4. 4

    Why does -d return true on empty variable

  5. 5

    Why does strcat not work with empty string in C?

  6. 6

    Why does my empty SD-Card is not empty

  7. 7

    Why does indexOf on an empty array does not return -1?

  8. 8

    Why does this create an infinite render loop with React hooks?

  9. 9

    Python saving empty plot

  10. 10

    Matplotlib: Check for empty plot

  11. 11

    Bokeh plot is empty

  12. 12

    Why does play.libs.Json.toJson return an empty object?

  13. 13

    Why does play.libs.Json.toJson return an empty object?

  14. 14

    Why does Azure Application Gateway require an empty subnet

  15. 15

    Why does MongoDB $size returns 1 for an empty sub-array?

  16. 16

    Why does `a.is_a? Array && !a.empty?` raise NoMethodError?

  17. 17

    Why does an empty string literal in a multidimensional array decay to a null pointer?

  18. 18

    Why does useCallback with an empty dependency array not return the same function?

  19. 19

    Why does writing empty std::istringstream.rdbuf() set failbit?

  20. 20

    Why does my database gets empty on adding data to another database?

  21. 21

    Why does crypto.subtle.digest return an empty Object

  22. 22

    Why does console.log wrongly print an empty array?

  23. 23

    Graphs, vertices, STL lists: Why does list come out empty?

  24. 24

    Glyphicon does not render to the template

  25. 25

    Image does not render with KineticJS

  26. 26

    Why does stacked bar plot change when add facet in r ggplot2

  27. 27

    Why does multiple inheritance increase the size of the object despite the bases being empty?

  28. 28

    Why does a leading null value in an array cause string.Join() to return empty string?

  29. 29

    Why does string.Join(" ", new object[] { null, "a", null, "b"}) retruns string.Empty?

ホットタグ

アーカイブ