Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: How do I write a dot over letters/variables, signifying the time derivative in physics?

I am looking for a way to place a bold dot above letters/variables to signify the time derivative. Ideally for both Python itself, but mainly for matplotlib axes.

I would expect something similar like:

print(u'1\u0305')

Although this is a very basic question, I cannot find anything, especially, because the term "dot notation" in Python is something completely different.

Thank you in advance.

like image 775
Thomas Avatar asked Dec 18 '25 16:12

Thomas


2 Answers

The value (unicode code point) for a dot above letters (combining dot above) is '\u0307', so combining it with any letter will give you that letter but with a dot above.

dot = '\u0307'
print('n' + dot)  # ṅ
print('a' + dot)  # ȧ
print('v' + dot)  # v̇

An arrow right above is often used if you want these to refer to a vector.

arrow = '\u20D7'
print('n' + arrow)  # n⃗
print('a' + arrow)  # a⃗
print('v' + arrow)  # v⃗

Alternatively, you could use a combining macron.

macron = '\u0304'
print('n' + macron)  # n̄
print('a' + macron)  # ā
print('v' + macron)  # v̄
like image 134
Ted Klein Bergman Avatar answered Dec 21 '25 06:12

Ted Klein Bergman


Use LaTeX notation with matplotlib.

import numpy as np
from matplotlib import pyplot as plt

plt.plot(np.random.random((5,)))
plt.xlabel('x')
plt.ylabel(r'$\dot{y}$')

enter image description here

You can name your variables using unicode characters like Ted showed, but in my opinion that just makes programming more difficult because standard keyboards don't have a way to type those characters easily.

like image 36
Pranav Hosangadi Avatar answered Dec 21 '25 06:12

Pranav Hosangadi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!