No visible text() when using matplotlib.pyplot

sdk

matplotlib==1.5.2 pylab==0.1.3

I am trying to reproduce a graph from the course "CS224d Deep Learning for NLP", Lecture 2.

It should look the following way:

enter image description here

I am using the following code:

import numpy as np
import matplotlib.pyplot as plt

la = np.linalg

words = ['I', 'like', 'enjoy', 'deep', 'learning', 'NLP', 'flying', '.'] 

X = np.array([[0,2,1,0,0,0,0,0],
              [2,0,0,1,0,1,0,0],
              [1,0,0,0,0,0,1,0],
              [0,1,0,0,1,0,0,0],
              [0,0,0,1,0,0,0,1],
              [0,1,0,0,0,0,0,1],
              [0,0,1,0,0,0,0,1],
              [0,0,0,0,1,1,1,0]])

U, s, Vh = la.svd(X, full_matrices=False)

for i in xrange(len(words)):
    plt.text(U[i,0], U[i,1], words[i])

plt.autoscale()
plt.show()

However, the words don't appear on the graph.

If I remove the instruction

plt.autoscale()
  • I can see some text plotted in the corner, but the axis range is wrong.

If I use this instruction, then I see no text at all, even if I call text() once again.

I have seen solutions with using subplots and setting the exact ranges for x and y axis, but this seems to be unnecessarily complex.

What else can I try?

p-robot

It shows the words when you set axis limits to show the text as per this answer below.

import numpy as np
import matplotlib.pyplot as plt

la = np.linalg

words = ['I', 'like', 'enjoy', 'deep', 'learning', 'NLP', 'flying', '.'] 

X = np.array([[0,2,1,0,0,0,0,0],
              [2,0,0,1,0,1,0,0],
              [1,0,0,0,0,0,1,0],
              [0,1,0,0,1,0,0,0],
              [0,0,0,1,0,0,0,1],
              [0,1,0,0,0,0,0,1],
              [0,0,1,0,0,0,0,1],
              [0,0,0,0,1,1,1,0]])

U, s, Vh = la.svd(X, full_matrices=False)

fig, ax = plt.subplots()
for i in xrange(len(words)):
    ax.text(U[i,0], U[i,1], words[i])

ax.set_xlim([-0.8, 0.2])
ax.set_ylim([-0.8, 0.8])
plt.show()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

No visible text() when using matplotlib.pyplot

From Dev

How to show node labels when using matplotlib.pyplot?

From Dev

How to determine the colours when using matplotlib.pyplot.imshow()?

From Dev

How to show node labels when using matplotlib.pyplot?

From Dev

Matplotlib TypeError when importing matplotlib.pyplot

From Dev

Heatmap with text in each cell with matplotlib's pyplot

From Dev

How to return only visible text when using Scrapy

From Dev

How to remove outline of circle marker when using pyplot.plot in matplotlib

From Dev

Visualize MNIST dataset using OpenCV or Matplotlib/Pyplot

From Dev

Using multiple keywords in pyplot.axis in matplotlib

From Dev

Visualize MNIST dataset using OpenCV or Matplotlib/Pyplot

From Java

"UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm

From Dev

"UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm

From Dev

matplotlib: override underscore in string when using LaTeX in text box

From Dev

Plots are not visible using matplotlib plt.show()

From Dev

matplotlib.pyplot.scatter() loses color when importing seaborn package?

From Dev

How do I display dates when plotting in matplotlib.pyplot?

From Dev

Random nan errors when importing matplotlib.pyplot

From Dev

When trying to import Matplotlib.pyplot, get "UnicodeDecodeError"

From Dev

tkinter error when trying to import matplotlib.pyplot in Arch Linux

From Dev

"ValueError: year is out of range" when attempting to use matplotlib pyplot

From Dev

ActionBar not visible when using tabs

From Dev

Adding legends to plots when not using the pyplot interface

From Dev

Plotting data from csv using matplotlib.pyplot

From Dev

Plotting a decision boundary separating 2 classes using Matplotlib's pyplot

From Dev

Using passed axis objects in a matplotlib.pyplot figure?

From Dev

displaying Mandelbrot set in python using matplotlib.pyplot and numpy

From Dev

When to use the matplotlib.pyplot class and when to use the plot object (matplotlib.collections.PathCollection)

From Dev

StatusStrip label not visible when text too long

Related Related

  1. 1

    No visible text() when using matplotlib.pyplot

  2. 2

    How to show node labels when using matplotlib.pyplot?

  3. 3

    How to determine the colours when using matplotlib.pyplot.imshow()?

  4. 4

    How to show node labels when using matplotlib.pyplot?

  5. 5

    Matplotlib TypeError when importing matplotlib.pyplot

  6. 6

    Heatmap with text in each cell with matplotlib's pyplot

  7. 7

    How to return only visible text when using Scrapy

  8. 8

    How to remove outline of circle marker when using pyplot.plot in matplotlib

  9. 9

    Visualize MNIST dataset using OpenCV or Matplotlib/Pyplot

  10. 10

    Using multiple keywords in pyplot.axis in matplotlib

  11. 11

    Visualize MNIST dataset using OpenCV or Matplotlib/Pyplot

  12. 12

    "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm

  13. 13

    "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm

  14. 14

    matplotlib: override underscore in string when using LaTeX in text box

  15. 15

    Plots are not visible using matplotlib plt.show()

  16. 16

    matplotlib.pyplot.scatter() loses color when importing seaborn package?

  17. 17

    How do I display dates when plotting in matplotlib.pyplot?

  18. 18

    Random nan errors when importing matplotlib.pyplot

  19. 19

    When trying to import Matplotlib.pyplot, get "UnicodeDecodeError"

  20. 20

    tkinter error when trying to import matplotlib.pyplot in Arch Linux

  21. 21

    "ValueError: year is out of range" when attempting to use matplotlib pyplot

  22. 22

    ActionBar not visible when using tabs

  23. 23

    Adding legends to plots when not using the pyplot interface

  24. 24

    Plotting data from csv using matplotlib.pyplot

  25. 25

    Plotting a decision boundary separating 2 classes using Matplotlib's pyplot

  26. 26

    Using passed axis objects in a matplotlib.pyplot figure?

  27. 27

    displaying Mandelbrot set in python using matplotlib.pyplot and numpy

  28. 28

    When to use the matplotlib.pyplot class and when to use the plot object (matplotlib.collections.PathCollection)

  29. 29

    StatusStrip label not visible when text too long

HotTag

Archive