Map y dimension of current plot to plotly's domain space. The bbox used to locate an axes object in mpl differs from the method used to locate axes in plotly. The mpl version locates each axes in the figure so that axes in a single-plot figure might have the bounds, [0.125, 0.125, 0
(mpl_plot_bounds, mpl_max_y_bounds)
| 189 | |
| 190 | |
| 191 | def convert_y_domain(mpl_plot_bounds, mpl_max_y_bounds): |
| 192 | """Map y dimension of current plot to plotly's domain space. |
| 193 | |
| 194 | The bbox used to locate an axes object in mpl differs from the |
| 195 | method used to locate axes in plotly. The mpl version locates each |
| 196 | axes in the figure so that axes in a single-plot figure might have |
| 197 | the bounds, [0.125, 0.125, 0.775, 0.775] (x0, y0, width, height), |
| 198 | in mpl's figure coordinates. However, the axes all share one space in |
| 199 | plotly such that the domain will always be [0, 0, 1, 1] |
| 200 | (x0, y0, x1, y1). To convert between the two, the mpl figure bounds |
| 201 | need to be mapped to a [0, 1] domain for x and y. The margins set |
| 202 | upon opening a new figure will appropriately match the mpl margins. |
| 203 | |
| 204 | Optionally, setting margins=0 and simply copying the domains from |
| 205 | mpl to plotly would place axes appropriately. However, |
| 206 | this would throw off axis and title labeling. |
| 207 | |
| 208 | Positional arguments: |
| 209 | mpl_plot_bounds -- the (x0, y0, width, height) params for current ax ** |
| 210 | mpl_max_y_bounds -- overall (y0, y1) bounds for all axes ** |
| 211 | |
| 212 | ** these are all specified in mpl figure coordinates |
| 213 | |
| 214 | """ |
| 215 | mpl_y_dom = [mpl_plot_bounds[1], mpl_plot_bounds[1] + mpl_plot_bounds[3]] |
| 216 | plotting_height = mpl_max_y_bounds[1] - mpl_max_y_bounds[0] |
| 217 | y0 = (mpl_y_dom[0] - mpl_max_y_bounds[0]) / plotting_height |
| 218 | y1 = (mpl_y_dom[1] - mpl_max_y_bounds[0]) / plotting_height |
| 219 | return [y0, y1] |
| 220 | |
| 221 | |
| 222 | def display_to_paper(x, y, layout): |