Python matplotlib.pyplot.twinx() Examples
The following are 29
code examples of matplotlib.pyplot.twinx().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.pyplot
, or try the search function
.
Example #1
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def shared_axis_remover(request): def _helper_x(ax): ax2 = ax.twinx() ax2.remove() ax.set_xlim(0, 15) r = ax.xaxis.get_major_locator()() assert r[-1] > 14 def _helper_y(ax): ax2 = ax.twiny() ax2.remove() ax.set_ylim(0, 15) r = ax.yaxis.get_major_locator()() assert r[-1] > 14 return {"x": _helper_x, "y": _helper_y}[request.param]
Example #2
Source File: test_axes.py From coffeegrindsize with MIT License | 6 votes |
def shared_axis_remover(request): def _helper_x(ax): ax2 = ax.twinx() ax2.remove() ax.set_xlim(0, 15) r = ax.xaxis.get_major_locator()() assert r[-1] > 14 def _helper_y(ax): ax2 = ax.twiny() ax2.remove() ax.set_ylim(0, 15) r = ax.yaxis.get_major_locator()() assert r[-1] > 14 return {"x": _helper_x, "y": _helper_y}[request.param]
Example #3
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_twin_axis_locaters_formatters(): vals = np.linspace(0, 1, num=5, endpoint=True) locs = np.sin(np.pi * vals / 2.0) majl = plt.FixedLocator(locs) minl = plt.FixedLocator([0.1, 0.2, 0.3]) fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) ax1.plot([0.1, 100], [0, 1]) ax1.yaxis.set_major_locator(majl) ax1.yaxis.set_minor_locator(minl) ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%08.2lf')) ax1.yaxis.set_minor_formatter(plt.FixedFormatter(['tricks', 'mind', 'jedi'])) ax1.xaxis.set_major_locator(plt.LinearLocator()) ax1.xaxis.set_minor_locator(plt.FixedLocator([15, 35, 55, 75])) ax1.xaxis.set_major_formatter(plt.FormatStrFormatter('%05.2lf')) ax1.xaxis.set_minor_formatter(plt.FixedFormatter(['c', '3', 'p', 'o'])) ax2 = ax1.twiny() ax3 = ax1.twinx()
Example #4
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_twinx_cla(): fig, ax = plt.subplots() ax2 = ax.twinx() ax3 = ax2.twiny() plt.draw() assert not ax2.xaxis.get_visible() assert not ax2.patch.get_visible() ax2.cla() ax3.cla() assert not ax2.xaxis.get_visible() assert not ax2.patch.get_visible() assert ax2.yaxis.get_visible() assert ax3.xaxis.get_visible() assert not ax3.patch.get_visible() assert not ax3.yaxis.get_visible() assert ax.xaxis.get_visible() assert ax.patch.get_visible() assert ax.yaxis.get_visible()
Example #5
Source File: test_axes.py From coffeegrindsize with MIT License | 6 votes |
def test_twinx_cla(): fig, ax = plt.subplots() ax2 = ax.twinx() ax3 = ax2.twiny() plt.draw() assert not ax2.xaxis.get_visible() assert not ax2.patch.get_visible() ax2.cla() ax3.cla() assert not ax2.xaxis.get_visible() assert not ax2.patch.get_visible() assert ax2.yaxis.get_visible() assert ax3.xaxis.get_visible() assert not ax3.patch.get_visible() assert not ax3.yaxis.get_visible() assert ax.xaxis.get_visible() assert ax.patch.get_visible() assert ax.yaxis.get_visible()
Example #6
Source File: test_axes.py From coffeegrindsize with MIT License | 6 votes |
def test_twin_axis_locaters_formatters(): vals = np.linspace(0, 1, num=5, endpoint=True) locs = np.sin(np.pi * vals / 2.0) majl = plt.FixedLocator(locs) minl = plt.FixedLocator([0.1, 0.2, 0.3]) fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) ax1.plot([0.1, 100], [0, 1]) ax1.yaxis.set_major_locator(majl) ax1.yaxis.set_minor_locator(minl) ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%08.2lf')) ax1.yaxis.set_minor_formatter(plt.FixedFormatter(['tricks', 'mind', 'jedi'])) ax1.xaxis.set_major_locator(plt.LinearLocator()) ax1.xaxis.set_minor_locator(plt.FixedLocator([15, 35, 55, 75])) ax1.xaxis.set_major_formatter(plt.FormatStrFormatter('%05.2lf')) ax1.xaxis.set_minor_formatter(plt.FixedFormatter(['c', '3', 'p', 'o'])) ax2 = ax1.twiny() ax3 = ax1.twinx()
Example #7
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 6 votes |
def shared_axis_remover(request): def _helper_x(ax): ax2 = ax.twinx() ax2.remove() ax.set_xlim(0, 15) r = ax.xaxis.get_major_locator()() assert r[-1] > 14 def _helper_y(ax): ax2 = ax.twiny() ax2.remove() ax.set_ylim(0, 15) r = ax.yaxis.get_major_locator()() assert r[-1] > 14 return {"x": _helper_x, "y": _helper_y}[request.param]
Example #8
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_twinx_cla(): fig, ax = plt.subplots() ax2 = ax.twinx() ax3 = ax2.twiny() plt.draw() assert not ax2.xaxis.get_visible() assert not ax2.patch.get_visible() ax2.cla() ax3.cla() assert not ax2.xaxis.get_visible() assert not ax2.patch.get_visible() assert ax2.yaxis.get_visible() assert ax3.xaxis.get_visible() assert not ax3.patch.get_visible() assert not ax3.yaxis.get_visible() assert ax.xaxis.get_visible() assert ax.patch.get_visible() assert ax.yaxis.get_visible()
Example #9
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_twin_axis_locaters_formatters(): vals = np.linspace(0, 1, num=5, endpoint=True) locs = np.sin(np.pi * vals / 2.0) majl = plt.FixedLocator(locs) minl = plt.FixedLocator([0.1, 0.2, 0.3]) fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) ax1.plot([0.1, 100], [0, 1]) ax1.yaxis.set_major_locator(majl) ax1.yaxis.set_minor_locator(minl) ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%08.2lf')) ax1.yaxis.set_minor_formatter(plt.FixedFormatter(['tricks', 'mind', 'jedi'])) ax1.xaxis.set_major_locator(plt.LinearLocator()) ax1.xaxis.set_minor_locator(plt.FixedLocator([15, 35, 55, 75])) ax1.xaxis.set_major_formatter(plt.FormatStrFormatter('%05.2lf')) ax1.xaxis.set_minor_formatter(plt.FixedFormatter(['c', '3', 'p', 'o'])) ax2 = ax1.twiny() ax3 = ax1.twinx()
Example #10
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_twin_spines_on_top(): matplotlib.rcParams['axes.linewidth'] = 48.0 matplotlib.rcParams['lines.linewidth'] = 48.0 fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) data = np.array([[1000, 1100, 1200, 1250], [310, 301, 360, 400]]) ax2 = ax1.twinx() ax1.plot(data[0], data[1]/1E3, color='#BEAED4') ax1.fill_between(data[0], data[1]/1E3, color='#BEAED4', alpha=.8) ax2.plot(data[0], data[1]/1E3, color='#7FC97F') ax2.fill_between(data[0], data[1]/1E3, color='#7FC97F', alpha=.5) # Reuse testcase from above for a labeled data test data = {"i": data[0], "j": data[1]/1E3} fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) ax2 = ax1.twinx() ax1.plot("i", "j", color='#BEAED4', data=data) ax1.fill_between("i", "j", color='#BEAED4', alpha=.8, data=data) ax2.plot("i", "j", color='#7FC97F', data=data) ax2.fill_between("i", "j", color='#7FC97F', alpha=.5, data=data)
Example #11
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_subplot_key_hash(): ax = plt.subplot(np.float64(5.5), np.int64(1), np.float64(1.2)) ax.twinx() assert ax.get_subplotspec().get_geometry() == (5, 1, 0, 0)
Example #12
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_twinx_knows_limits(): fig, ax = plt.subplots() ax.axvspan(1, 2) xtwin = ax.twinx() xtwin.plot([0, 0.5], [1, 2]) # control axis fig2, ax2 = plt.subplots() ax2.axvspan(1, 2) ax2.plot([0, 0.5], [1, 2]) assert_array_equal(xtwin.viewLim.intervalx, ax2.viewLim.intervalx)
Example #13
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_twin_inherit_autoscale_setting(): fig, ax = plt.subplots() ax_x_on = ax.twinx() ax.set_autoscalex_on(False) ax_x_off = ax.twinx() assert ax_x_on.get_autoscalex_on() assert not ax_x_off.get_autoscalex_on() ax_y_on = ax.twiny() ax.set_autoscaley_on(False) ax_y_off = ax.twiny() assert ax_y_on.get_autoscaley_on() assert not ax_y_off.get_autoscaley_on()
Example #14
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_twinx_axis_scales(): x = np.array([0, 0.5, 1]) y = 0.5 * x x2 = np.array([0, 1, 2]) y2 = 2 * x2 fig = plt.figure() ax = fig.add_axes((0, 0, 1, 1), autoscalex_on=False, autoscaley_on=False) ax.plot(x, y, color='blue', lw=10) ax2 = plt.twinx(ax) ax2.plot(x2, y2, 'r--', lw=5) ax.margins(0, 0) ax2.margins(0, 0)
Example #15
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_twin_with_aspect(twin): fig, ax = plt.subplots() # test twinx or twiny ax_twin = getattr(ax, 'twin{}'.format(twin))() ax.set_aspect(5) ax_twin.set_aspect(2) assert_array_equal(ax.bbox.extents, ax_twin.bbox.extents)
Example #16
Source File: burst_plot.py From FRETBursts with GNU General Public License v2.0 | 5 votes |
def _fitted_E_plot(d, i=0, F=1, no_E=False, ax=None, show_model=True, verbose=False, two_gauss_model=False, lw=2.5, color='k', alpha=0.5, fillcolor=None): """Plot a fitted model overlay on a FRET histogram.""" if ax is None: ax2 = gca() else: ax2 = plt.twinx(ax=ax) ax2.grid(False) if d.fit_E_curve and show_model: x = r_[-0.2:1.21:0.002] y = d.fit_E_model(x, d.fit_E_res[i, :]) scale = F*d.fit_E_model_F[i] if two_gauss_model: assert d.fit_E_res.shape[1] > 2 if d.fit_E_res.shape[1] == 5: m1, s1, m2, s2, a1 = d.fit_E_res[i, :] a2 = (1-a1) elif d.fit_E_res.shape[1] == 6: m1, s1, a1, m2, s2, a2 = d.fit_E_res[i, :] y1 = a1*normpdf(x, m1, s1) y2 = a2*normpdf(x, m2, s2) ax2.plot(x, scale*y1, ls='--', lw=lw, alpha=alpha, color=color) ax2.plot(x, scale*y2, ls='--', lw=lw, alpha=alpha, color=color) if fillcolor is None: ax2.plot(x, scale*y, lw=lw, alpha=alpha, color=color) else: ax2.fill_between(x, scale*y, lw=lw, alpha=alpha, edgecolor=color, facecolor=fillcolor, zorder=10) if verbose: print('Fit Integral:', np.trapz(scale*y, x)) ax2.axvline(d.E_fit[i], lw=3, color=red, ls='--', alpha=0.6) xtext = 0.6 if d.E_fit[i] < 0.6 else 0.2 if d.nch > 1 and not no_E: ax2.text(xtext, 0.81, "CH%d: $E_{fit} = %.3f$" % (i+1, d.E_fit[i]), transform=gca().transAxes, fontsize=16, bbox=dict(boxstyle='round', facecolor='#dedede', alpha=0.5))
Example #17
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_twinx_knows_limits(): fig, ax = plt.subplots() ax.axvspan(1, 2) xtwin = ax.twinx() xtwin.plot([0, 0.5], [1, 2]) # control axis fig2, ax2 = plt.subplots() ax2.axvspan(1, 2) ax2.plot([0, 0.5], [1, 2]) assert_array_equal(xtwin.viewLim.intervalx, ax2.viewLim.intervalx)
Example #18
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_twin_with_aspect(twin): fig, ax = plt.subplots() # test twinx or twiny ax_twin = getattr(ax, 'twin{}'.format(twin))() ax.set_aspect(5) ax_twin.set_aspect(2) assert_array_equal(ax.bbox.extents, ax_twin.bbox.extents)
Example #19
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_twin_spines_on_top(): matplotlib.rcParams['axes.linewidth'] = 48.0 matplotlib.rcParams['lines.linewidth'] = 48.0 fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) data = np.array([[1000, 1100, 1200, 1250], [310, 301, 360, 400]]) ax2 = ax1.twinx() ax1.plot(data[0], data[1]/1E3, color='#BEAED4') ax1.fill_between(data[0], data[1]/1E3, color='#BEAED4', alpha=.8) ax2.plot(data[0], data[1]/1E3, color='#7FC97F') ax2.fill_between(data[0], data[1]/1E3, color='#7FC97F', alpha=.5) # Reuse testcase from above for a labeled data test data = {"i": data[0], "j": data[1]/1E3} fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) ax2 = ax1.twinx() ax1.plot("i", "j", color='#BEAED4', data=data) ax1.fill_between("i", "j", color='#BEAED4', alpha=.8, data=data) ax2.plot("i", "j", color='#7FC97F', data=data) ax2.fill_between("i", "j", color='#7FC97F', alpha=.5, data=data)
Example #20
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_subplot_key_hash(): ax = plt.subplot(np.float64(5.5), np.int64(1), np.float64(1.2)) ax.twinx() assert ax.get_subplotspec().get_geometry() == (5, 1, 0, 0)
Example #21
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_twin_inherit_autoscale_setting(): fig, ax = plt.subplots() ax_x_on = ax.twinx() ax.set_autoscalex_on(False) ax_x_off = ax.twinx() assert ax_x_on.get_autoscalex_on() assert not ax_x_off.get_autoscalex_on() ax_y_on = ax.twiny() ax.set_autoscaley_on(False) ax_y_off = ax.twiny() assert ax_y_on.get_autoscaley_on() assert not ax_y_off.get_autoscaley_on()
Example #22
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_twinx_axis_scales(): x = np.array([0, 0.5, 1]) y = 0.5 * x x2 = np.array([0, 1, 2]) y2 = 2 * x2 fig = plt.figure() ax = fig.add_axes((0, 0, 1, 1), autoscalex_on=False, autoscaley_on=False) ax.plot(x, y, color='blue', lw=10) ax2 = plt.twinx(ax) ax2.plot(x2, y2, 'r--', lw=5) ax.margins(0, 0) ax2.margins(0, 0)
Example #23
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_twin_with_aspect(twin): fig, ax = plt.subplots() # test twinx or twiny ax_twin = getattr(ax, 'twin{}'.format(twin))() ax.set_aspect(5) ax_twin.set_aspect(2) assert_array_equal(ax.bbox.extents, ax_twin.bbox.extents)
Example #24
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_twin_spines_on_top(): matplotlib.rcParams['axes.linewidth'] = 48.0 matplotlib.rcParams['lines.linewidth'] = 48.0 fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) data = np.array([[1000, 1100, 1200, 1250], [310, 301, 360, 400]]) ax2 = ax1.twinx() ax1.plot(data[0], data[1]/1E3, color='#BEAED4') ax1.fill_between(data[0], data[1]/1E3, color='#BEAED4', alpha=.8) ax2.plot(data[0], data[1]/1E3, color='#7FC97F') ax2.fill_between(data[0], data[1]/1E3, color='#7FC97F', alpha=.5) # Reuse testcase from above for a labeled data test data = {"i": data[0], "j": data[1]/1E3} fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) ax2 = ax1.twinx() ax1.plot("i", "j", color='#BEAED4', data=data) ax1.fill_between("i", "j", color='#BEAED4', alpha=.8, data=data) ax2.plot("i", "j", color='#7FC97F', data=data) ax2.fill_between("i", "j", color='#7FC97F', alpha=.5, data=data)
Example #25
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_subplot_key_hash(): ax = plt.subplot(np.float64(5.5), np.int64(1), np.float64(1.2)) ax.twinx() assert ax.get_subplotspec().get_geometry() == (5, 1, 0, 0)
Example #26
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_twin_inherit_autoscale_setting(): fig, ax = plt.subplots() ax_x_on = ax.twinx() ax.set_autoscalex_on(False) ax_x_off = ax.twinx() assert ax_x_on.get_autoscalex_on() assert not ax_x_off.get_autoscalex_on() ax_y_on = ax.twiny() ax.set_autoscaley_on(False) ax_y_off = ax.twiny() assert ax_y_on.get_autoscaley_on() assert not ax_y_off.get_autoscaley_on()
Example #27
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_twinx_axis_scales(): x = np.array([0, 0.5, 1]) y = 0.5 * x x2 = np.array([0, 1, 2]) y2 = 2 * x2 fig = plt.figure() ax = fig.add_axes((0, 0, 1, 1), autoscalex_on=False, autoscaley_on=False) ax.plot(x, y, color='blue', lw=10) ax2 = plt.twinx(ax) ax2.plot(x2, y2, 'r--', lw=5) ax.margins(0, 0) ax2.margins(0, 0)
Example #28
Source File: plotting.py From armi with Apache License 2.0 | 4 votes |
def buVsTime(reactor, scalars): r""" produces a burnup and DPA vs. time plot for this case Will add a second axis containing DPA if the scalar column maxDPA exists. Parameters ---------- scalars : dict Scalar values for this case """ plt.figure() try: plt.plot(scalars["time"], scalars["maxBuI"], ".-", label="Driver") except ValueError: runLog.warning( "Incompatible axis length in burnup plot. Time has {0}, bu has {1}. Skipping" "".format(len(scalars["time"]), len(scalars["maxBuI"])) ) plt.close(1) return plt.plot(scalars["time"], scalars["maxBuF"], ".-", label="Feed") plt.xlabel("Time (yr)") plt.ylabel("BU (%FIMA)") plt.grid(color="0.70") plt.legend(loc="lower left") title = "Maximum burnup" if scalars["maxDPA"]: plt.twinx() plt.plot(scalars["time"], scalars["maxDPA"], "r--", label="dpa") plt.legend(loc="lower right") plt.ylabel("dpa") title += " and DPA" title += " for " + reactor.name plt.title(title) plt.legend(loc="lower right") figName = reactor.name + ".bu." + settings.getMasterCs()["outputFileExtension"] plt.savefig(figName) plt.close(1) report.setData("Burnup Plot", os.path.abspath(figName), report.BURNUP_PLOT)
Example #29
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 4 votes |
def test_twinx_knows_limits(): fig, ax = plt.subplots() ax.axvspan(1, 2) xtwin = ax.twinx() xtwin.plot([0, 0.5], [1, 2]) # control axis fig2, ax2 = plt.subplots() ax2.axvspan(1, 2) ax2.plot([0, 0.5], [1, 2]) assert_array_equal(xtwin.viewLim.intervalx, ax2.viewLim.intervalx)