Hello. I am trying to learn the Python language + the Matplotlib library and at the moment I am stuck with some points: https://i.stack.imgur.com/qFz7e.png

The first:

I do not know how I can remove (in the window), notations (axex: x, Y and their coordinates) that can be seen on the screen?

Second:

I would like to know - can I set the scroll bar on any chart? I mean, I need a fixed width on the chart and if the content (some number of points or Japanese candles) will grow inside it (in width) - I need the appearance of a scroll bar from the bottom of the chart.

Can this be implemented on the netival Python + matplotlib? (without wx Python, tkinter, etc., etc.)

PS I would be grateful for any constructive advice.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

As for the scrollbar, it can be done using the "Slider" widget, but it will not be very easy.

Try this example:

from matplotlib.widgets import Slider import math import matplotlib.pyplot as plt fig, ax = plt.subplots() plt.subplots_adjust(left=0.25, bottom=0.25) t = [i / 100. for i in range(0, int(math.pi) * 100, 1)] s = [math.sin(i * 20) for i in t] l, = plt.plot(t, s, lw=2, color='red') plt.axis([0, 1, -10, 10]) axcolor = 'gray' ax_x_pos = plt.axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor) wsize = 10 x_pos = Slider(ax_x_pos, 'Position', 0, len(t) - wsize - 1, valfmt='%d', valinit=0) ax.set_xlim(t[0], t[wsize]) ax.set_ylim(-1.1, 1.1) def update(val): print(x_pos.val) pos = int(x_pos.val) ax.set_xlim(t[pos], t[pos + wsize]) fig.canvas.draw_idle() x_pos.on_changed(update) plt.show() 

To remove the display of coordinates, it is necessary to replace the output function with a "dummy":

 import matplotlib.pyplot as plt plt.figure(1) plt.plot([1, 2, 3]) plt.gca().format_coord = lambda x, y: '' plt.show() 
  • Thanks for the example. This is what you need. And at the expense of the white field from the bottom (with notations) - you do not accidentally know how this case can be rolled up? - Mike Kharkov
  • Added in response an example of removing the output coordinates. - Avernial
  • Such a moment I also wanted to find out for myself for the future: Will it be impossible to implement a vertical scroll in this way? (so far from the fact that I naguglil - it was said that it was impossible.) + I wanted to clarify the moment when the slider was disconnected - the dock says (if I did not mess up anything) what the following function is responsible for: disconnect (cid) Question: How can I not apply it I can understand (where to connect this code + with what parameter instead of "cid")? (what, for example, if I had few elements on the chart - the slider disappeared + could appear again if the number of elements increases ..) - Mike Kharkov
  • Vertical scrolling can be done in the same way. Only instead of setting the range in x set_xlim will be a call to y set_ylim . cid is the connection ID. In my example, cid can be obtained like this: cid = x_pos.on_changed(update) , and then disable the slider: x_pos.disconnect(cid) . - Avernial
  • But it is better not to disconnect, but simply not to connect the signal. - Avernial