Do text and / or number input fields exist for matplotlib
?
I have seen the widget Slider
, but that is something different. I want a simple number input field.
The matplotlib.pyplot.text () function is used to add text inside the plot. The syntax adds text at an arbitrary location of the axes. It also supports mathematical expressions. Syntax: matplotlib.pyplot.text (x, y, s, fontdict=None, **kwargs) fontdict – optional parameter. It overrides the default text properties
Matplotlib includes its own matplotlib.font_manager (thanks to Paul Barrett), which implements a cross platform, W3C compliant font finding algorithm. The user has a great deal of control over text properties (font size, font weight, text location and color, etc.) with sensible defaults set in the rc file .
Matplotlib has extensive text support, including support for mathematical expressions, truetype support for raster and vector outputs, newline separated text with arbitrary rotations, and unicode support. Because it embeds fonts directly in output documents, e.g., for postscript or PDF, what you see on the screen is what you get in the hardcopy.
All the labelling in this tutorial can be changed by manipulating the matplotlib.font_manager.FontProperties method, or by named kwargs to set_xlabel Finally, we can use native TeX rendering in all text objects and have multiple lines:
You are looking for the TextBox interactive widget, which was added in 2.1:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.2)
t = np.arange(-2.0, 2.0, 0.001)
ydata = t ** 2
initial_text = "t ** 2"
l, = plt.plot(t, ydata, lw=2)
def submit(text):
ydata = eval(text)
l.set_ydata(ydata)
ax.set_ylim(np.min(ydata), np.max(ydata))
plt.draw()
axbox = plt.axes([0.1, 0.05, 0.8, 0.075])
text_box = TextBox(axbox, 'Evaluate', initial=initial_text)
text_box.on_submit(submit)
plt.show()
There currently exists no widgets that could be used to enter numbers as text. If you had a small selection of discrete numbers then you could use a RadioButton or you could use a slider as you've already suggested.
Your best would be to build a full GUI using Tkinter. This would allow you to add whatever GUI elements you need. It's also possible to embed matplotlib graphs in Tkinter, as shown in the two examples here and here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With