Reputation: 12645
I have a candlestick chart that is dinamically created for different lengths and stocks. The chart is created first (the creation of the chart is contained in a function "createChart") and not shown until the moment the user presses on the button "Show Chart", that will hence call the instruction .show() and display the plot previously created. When the user clicks on the button he gets the following result:
However, what I would like to get is a chart that is already zoomed-in, let's say, on the last 5% of data. So what I would like to get is when the user presses on the button "Show Chart" the plot (that has been already fully created into the "createChart" function) should zoom on the last couple of months, so Nov 2012 - Dec 2012, but so allowing the user to scroll back/forward:
Hence my question is: to make the chart more user-friendly and zoom-in directly on the last observations (that in finance are the most relevant), but still giving the user the possibility of slide the chart and going back or forward as he wishes, how could I customize the .show() method to get this result?
Upvotes: 2
Views: 791
Reputation: 2264
I propose you to use the navigation toolbar tools; here is an example:
from pylab import *
x=[1,2,2,3,5]
y=[2,3,4,5,6]
fig=figure() # create and store a figure
tb=fig.canvas.toolbar # get the toolbar of the figure
ax=fig.add_subplot(1,1,1) # add axes to the figure
ax.plot(x,y) # plot
tb.push_current() # save the current zoom in the view stack
ax.set_xlim([1,3]) # change xlims
ax.set_ylim([2,5]) # change ylims
tb.push_current() # save the new position in the view stack
show() # show the figure
Upvotes: 4
Reputation: 1082
What about xlim((from, to))
and ylim((from, to))
?
It limits only the view, not what data is actually plotted. You might have to pay attention to the case where you have a whole lot of data, then the plot() or show() command takes ages to load.
Upvotes: 1