Note that this works for Line2D objects plotted via ax.plot. The best recommendation I can make is extract the data from the axes you want to copy, and manually plot that into a new axes object that is sized to your liking. You are probably trying to re-use an artist in more than one Axes which is not supported >RuntimeError: Can not put single artist in more than one figure`Īnd attempting to add a line that was drawn in ax1 to a second axes ax2 on the same figure raises an error: fig1 = plt.figure() This discussion on Github may explain it to some degree.įor example, attempting to add a line from an axes defined on fig1 to an axes on a different figure fig2 raises an error: import matplotlib.pyplot as plt In fact, no artist (line, text, legend) defined in one axes may be added to another axes. It is the plotting library that I prefer but for no specific reason.I can't find anything in official documentation to back up what I'm saying, but my understanding is that it is impossible to "clone" an existing axes onto a new figure. # set legend only in one axis (but with all lines)Īx1.legend(lines, )īTW, I used matplotlib due to (my) convenience. # places the nex axis (ticks and description) below the other axesĪx.t_position(("outward", offest*i)) # additional offset # sets the ticks to be shown at the bottomĪx.tick_params(axis='x', direction='out',labelbottom=True) # creates another axes that shares the same y-axis This is why we need to set all these properties (where to show the axis, in which direction should the label and the ticks being placed) and a few nice things, such as the color of the label and the ticks. The problem is that matplotlib automatically places other axes on the opposite side (so 'top' in case of the x-axis and 'right' in the case of the y-axis). There is an example of how to create multiple axes in a single plot.īasically, you create another axis with twinx() and then set everything in such a way that it ends up nicely. The question is a bit tricky but feasible. One approach is to change the position of the title itself using fig.update_layout(title=dict()): fig.update_layout(Ĭomplete code for Plot 2 from plotly.subplots import make_subplots # not critical, but just to put a little air in thereįig.update_layout(xaxis1=dict(domain=),Įdit: Tighten the space between title and range. # extra data where xaxis4 is shared with subplot 2įig.update_layout(yaxis1=dict(domain=), # extra data where xaxis3 is shared with subplot 1 Title_text="Subplots with shared x-axes") Here's the result: PlotĬomplete code: from plotly.subplots import make_subplots The reason why you'll have to take domain into account is because the position attribute in point 3 can't be negative, and you'll have to make room for the double x-axes somehow. Make some final adjustments using fig.update_layout(, yaxis2=dict(domain=)) Then, adjust subplot 1 to make room for xaxis3 using: fig.update_layout(xaxis3=dict(anchor="free", overlaying="x1", position=0.0)) Set up a "regular" subplot using fig=make_subplots(rows=1, cols=2) and include two traces as described here.Īdd a third trace with its own xaxis using fig.add_trace(go.Scatter([.[, xaxis="x3")) You'll need a precise combination of make_subplots(rows=1, cols=2), add_traces() and fig.update_layout(xaxis=dict(domain=.):
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |