3

I have tried a lot with different methods with no success. I think its easy but... First I have a simple line plot and below a slider which is working good updating the plot as I wish. But no I want to have the values below the slider. No way for now as already said, maybe the reason is the bad coding, I'm not the moste experienced one. This is a snippet of what I have. The code runs without problems but the labels (sl_xticks) are not seen.

   ...statements for the line plot up to here...
   ax_skal = plt.axes([0.25, 0.05, 0.65, 0.02], facecolor="lightgrey")
   sl_xticks = np.arange(0.6,2, 0.2)
   ax_skal.set_xticks(sl_xticks)    
   s_skal = Slider(ax_skal, 'time scale', 0.5, 2, valinit=1, valfmt='%0.1f')
   s_skal.vline.set_color('blue')

Any (working) idea? ;-) I work with Python3 and all libraries updated. By the way, during my programming I have seen labels under the slider, but I forgot the way going there because it was wrong. The labels were taken from the line plot with a complete different use. I wonder that nobody has put an example until now, because I think its often necessary. Perhaps its too easy... Many thanks!

2 Answers2

3

You need to set the x-axis visible for your xticks setting to take effect:

s_skal = Slider(ax_skal, 'time scale', 0.5, 2, valinit=1, valfmt='%0.1f')
ax_skal.xaxis.set_visible(True)
ax_skal.set_xticks(sl_xticks) 
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • Thanks, this solved the problem. As easy as I thought there was something forgotten. – Fritze Friemel Feb 17 '17 at 19:45
  • This strategy [does not work anymore with matplotlib 3.5.1.](https://stackoverflow.com/questions/71186196/set-tick-labels-for-matplotlib-slider-widgets?noredirect=1&lq=1) – Mr. T Feb 20 '22 at 18:46
-1

Here is the link to the Matplotlib User Documentation, specifically for 'Text Properties and Layout'. I'd recommend saving this link as it has helped me out greatly with general questions and it gives real code examples of each topic for reference. Matplotlib User Doc.

pdel5
  • 93
  • 1
  • 8