Why I get error while trying to use LaTeX in plots' label

bluevoxel

I try to show:

enter image description here

...as my plots' x axis label. For this purpose I use the pylab.figtext() function, i.e:

py.figtext(0.5, 0.05, "$k=2,\left \langle \left | -k \right |;k \right \rangle, 
k\in \mathbb{N}_{+}\cup\left \{ 0 \right \}$", rotation='horizontal', size='12')

Unfortunately, I get error:

ValueError: 
$k=2,\left \langle \left | -k 
ight |;k 
ight 
angle, k\in \mathbb{N}_{+}\cup\left \{ 0 
ight \}$
^
Expected end of text (at char 0), (line:1, col:1)

Why is that? I thought, that I can use LaTeX freely. How should I format my text in figtext() method in order to achieve the aforementioned mathematical sentence? Thank you in advance.

Bas Swinckels

This can be fixed by a 1 letter correction:

py.figtext(0.5, 0.05, r"$k=2,\left \langle \left | -k \right |;k \right \rangle, 
k\in \mathbb{N}_{+}\cup\left \{ 0 \right \}$", rotation='horizontal', size='12')

Note the r before the string literal. The cause of the error is that several of the character combinations in your latex string are valid Python escape sequences for such things as tabs and new-lines. A string literal prefixed with an r (e.g. r"foo\nbar") makes Python interpret the string as a raw string literal, i.e. without converting the escaped character combinations to special characters.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why "SyntaxError: invalid label" when trying to use $.ajax to get JSON

From Dev

Why do I get a mismatched types error while trying to match a tuple?

From Dev

Why do I get error while trying to build an architecture with multiple inputs in Keras?

From Dev

Why do I get a mismatched types error while trying to match a tuple?

From Dev

Why do I get an `Incorrect Padding` Error while trying to decode my base32 string?

From Dev

why I get this error while starting eclipse

From Dev

Why do I get an error when trying to use a method in application_controller?

From Dev

Why do I get an undefined variable error when trying to use PHP in two sections of a page?

From Dev

Why do I get "Could not push back" error when trying to use the IBM Bluemix Document Conversion service?

From Dev

Why do I get a NullPointerException while trying to begin transaction?

From Dev

Error while trying to use polyval

From Dev

Why do I get a PHP error 406 when trying to use file_get_contents() function and how to solve it?

From Dev

Why I have this error trying to use the JavaScript substr() function?

From Dev

I am trying to create a test label from Shippo, however I get a rate error

From Dev

Why do I get BUILD SUCCESSFUL while I had an error?

From Dev

Why do I get this error when trying to map on a list of lists?

From Dev

Why i get 404 error trying to acess a rest?

From Dev

Why do i get this error when trying to check if in Corona sdk?

From Dev

Trying to get property of non-object error while trying to use eloquent relationship

From Dev

When I use while loop instead of if I get TLE error

From Dev

I am trying to write an equation in LaTeX and i have an error

From Java

Why do i get a laravel error while creating a new project?

From Dev

Why do I get an error with a foreach loop inside a while loop?

From Dev

Why do I get a "permission denied" error while installing a gem?

From Dev

Why do I get a column not found error while sorting a GridView

From Dev

Why am I getting an error when I am trying to insert a while loop?

From Dev

Why do I get a CannotAcquireResourceException while trying to connect, when I extend AbstractComboPooledDataSource?

From Dev

I get an error: An unexpected error occurred while trying to open file hola.jar

From Dev

Unknown label type error while I'm trying to fit x_train and y_train to Perceptron and MLPClassifier using Sklearn

Related Related

  1. 1

    Why "SyntaxError: invalid label" when trying to use $.ajax to get JSON

  2. 2

    Why do I get a mismatched types error while trying to match a tuple?

  3. 3

    Why do I get error while trying to build an architecture with multiple inputs in Keras?

  4. 4

    Why do I get a mismatched types error while trying to match a tuple?

  5. 5

    Why do I get an `Incorrect Padding` Error while trying to decode my base32 string?

  6. 6

    why I get this error while starting eclipse

  7. 7

    Why do I get an error when trying to use a method in application_controller?

  8. 8

    Why do I get an undefined variable error when trying to use PHP in two sections of a page?

  9. 9

    Why do I get "Could not push back" error when trying to use the IBM Bluemix Document Conversion service?

  10. 10

    Why do I get a NullPointerException while trying to begin transaction?

  11. 11

    Error while trying to use polyval

  12. 12

    Why do I get a PHP error 406 when trying to use file_get_contents() function and how to solve it?

  13. 13

    Why I have this error trying to use the JavaScript substr() function?

  14. 14

    I am trying to create a test label from Shippo, however I get a rate error

  15. 15

    Why do I get BUILD SUCCESSFUL while I had an error?

  16. 16

    Why do I get this error when trying to map on a list of lists?

  17. 17

    Why i get 404 error trying to acess a rest?

  18. 18

    Why do i get this error when trying to check if in Corona sdk?

  19. 19

    Trying to get property of non-object error while trying to use eloquent relationship

  20. 20

    When I use while loop instead of if I get TLE error

  21. 21

    I am trying to write an equation in LaTeX and i have an error

  22. 22

    Why do i get a laravel error while creating a new project?

  23. 23

    Why do I get an error with a foreach loop inside a while loop?

  24. 24

    Why do I get a "permission denied" error while installing a gem?

  25. 25

    Why do I get a column not found error while sorting a GridView

  26. 26

    Why am I getting an error when I am trying to insert a while loop?

  27. 27

    Why do I get a CannotAcquireResourceException while trying to connect, when I extend AbstractComboPooledDataSource?

  28. 28

    I get an error: An unexpected error occurred while trying to open file hola.jar

  29. 29

    Unknown label type error while I'm trying to fit x_train and y_train to Perceptron and MLPClassifier using Sklearn

HotTag

Archive