![]() ![]() In this case the automatic alpha tuning is off. Note that if no alpha value is provided to the plot command, the artist stores None as alpha value. Here I implemented it such that the alpha decreases when the figure size is decreased. For this reason, in my implementation the alpha value can only be decreased from the original value. This is not quite as straight forward as the marker size, because alpha values must not be larger than 1.0. I also fixed another bug, where the points in the scatter plot scaled wrongly - they should scale quadratic, not linear ( see here).įinally, as it was missing from the previous solution, I also added updating for the alpha value of the markers. ![]() Each Axes instance can be registered separately to the MarkerUpdater instance, so you could also have several subplots in one figure, of which some are updated and some not. In addition, do avoid all the global variables, I wrapped everything into a class called MarkerUpdater. Instead I added an extra call to () whenever the scaling changes (the if statement prevents infinite loops). Also ax.draw_artist() followed by a _idle() like in the linked answer did not really solve the problem (however, this might be platform/backend specific). At first the plots did not update correctly upon zooming. The main idea here is to only use one type of event, namely draw_event. ![]() Motivated by the comments below and this answer, I created another solution. The code has been tested in Pyton 2.7 and 3.6 with matplotlib 2.1.1. t_sizes(])įig.canvas.mpl_connect('resize_event', on_resize)Īx.nnect('xlim_changed', lim_change)Īx.nnect('ylim_changed', lim_change) Point_sizes = paths.get_sizes()įig_factor = min(w/fig_width,h/fig_height)įor line,size in zip(lines,line_sizes): from matplotlib import pyplot as pltįig, axes = plt.subplots(nrows=1, ncols = 2) If you'd rather want to scale with the larger factors, change the min to max in both event functions. As there are two limits defined - one for the x and one for the y direction, I used here the respective minima for the two factors. Both zooming (factor) and resizing of the figure (fig_factor) re-scale the points according to the scaling factors in figure size and x- and y- limits. Below is an example with two subplots, a line plot on the left and a scatter plot on the right. It's a bit tricky to account for both at the same time, but not impossible. You have to catch zoom and resize events separately. You can achieve what you want with matplotlib event handling. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |