Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Weird margins when using curvilinear axis

$
0
0

This example comes from Matplotlib's documentation. I'm running it inside Jupyter Lab. Here I attach the output figure:

import matplotlib.pyplot as pltimport numpy as npfrom matplotlib.projections import PolarAxesfrom matplotlib.transforms import Affine2Dfrom mpl_toolkits.axisartist import Axes, HostAxes, angle_helperfrom mpl_toolkits.axisartist.grid_helper_curvelinear import \    GridHelperCurveLineardef curvelinear_test1(fig):"""    Grid for custom transform."""    def tr(x, y): return x, y - x    def inv_tr(x, y): return x, y + x    grid_helper = GridHelperCurveLinear((tr, inv_tr))    ax1 = fig.add_subplot(1, 2, 1, axes_class=Axes, grid_helper=grid_helper)    # ax1 will have ticks and gridlines defined by the given transform (+    # transData of the Axes).  Note that the transform of the Axes itself    # (i.e., transData) is not affected by the given transform.    xx, yy = tr(np.array([3, 6]), np.array([5, 10]))    ax1.plot(xx, yy)    ax1.set_aspect(1)    ax1.set_xlim(0, 10)    ax1.set_ylim(0, 10)    ax1.axis["t"] = ax1.new_floating_axis(0, 3)    ax1.axis["t2"] = ax1.new_floating_axis(1, 7)    ax1.grid(True, zorder=0)fig = plt.figure()curvelinear_test1(fig)plt.show()

enter image description here

Note the weird top/bottom margins. Left/Right margins seems ok. If I execute this code inside a standard python interpreter, the picture looks like this:

enter image description here

Here, maybe there is too much top/bottom margin, and definitely too much right margin.

I've tried plt.tight_layout() just before plt.show(), but it does nothing in this case. I've looked at the source code of Axes/HostAxes but I couln't find anything obvious that would help fix these margins.

What can I try?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>