MCPcopy Index your code
hub / github.com/plotly/plotly.py / convert_x_domain

Function convert_x_domain

plotly/matplotlylib/mpltools.py:160–188  ·  view source on GitHub ↗

Map x 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_x_bounds)

Source from the content-addressed store, hash-verified

158
159
160def convert_x_domain(mpl_plot_bounds, mpl_max_x_bounds):
161 """Map x dimension of current plot to plotly's domain space.
162
163 The bbox used to locate an axes object in mpl differs from the
164 method used to locate axes in plotly. The mpl version locates each
165 axes in the figure so that axes in a single-plot figure might have
166 the bounds, [0.125, 0.125, 0.775, 0.775] (x0, y0, width, height),
167 in mpl's figure coordinates. However, the axes all share one space in
168 plotly such that the domain will always be [0, 0, 1, 1]
169 (x0, y0, x1, y1). To convert between the two, the mpl figure bounds
170 need to be mapped to a [0, 1] domain for x and y. The margins set
171 upon opening a new figure will appropriately match the mpl margins.
172
173 Optionally, setting margins=0 and simply copying the domains from
174 mpl to plotly would place axes appropriately. However,
175 this would throw off axis and title labeling.
176
177 Positional arguments:
178 mpl_plot_bounds -- the (x0, y0, width, height) params for current ax **
179 mpl_max_x_bounds -- overall (x0, x1) bounds for all axes **
180
181 ** these are all specified in mpl figure coordinates
182
183 """
184 mpl_x_dom = [mpl_plot_bounds[0], mpl_plot_bounds[0] + mpl_plot_bounds[2]]
185 plotting_width = mpl_max_x_bounds[1] - mpl_max_x_bounds[0]
186 x0 = (mpl_x_dom[0] - mpl_max_x_bounds[0]) / plotting_width
187 x1 = (mpl_x_dom[1] - mpl_max_x_bounds[0]) / plotting_width
188 return [x0, x1]
189
190
191def convert_y_domain(mpl_plot_bounds, mpl_max_y_bounds):

Callers 1

prep_xy_axisFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected