Can I have both twinx and twiny together (i.e. something like twinxy)? I want to put a CDF on a bar plot where the X axis of the bar plot is in log-scale. I cannot make the Ys together, because the bar plot y range is very large comparing [0,1] for CDF.
Any ideas?
Thanks,
You can combine the legend items by scooping out the original objects, here via the ax. get_* function to get the labels and the “handles”. You can think of handles as just points/lines/polygons that refer to individual parts of the legend.
Using subplots() method, create a figure and a set of subplots. Plot [1, 2, 3, 4, 5] data points on the left Y-axis scales. Using twinx() method, create a twin of Axes with a shared X-axis but independent Y-axis, ax2. Plot [11, 12, 31, 41, 15] data points on the right Y-axis scale, with blue color.
Create a new twin Axis sharing the x axis with ax. twinx() : the idea. fig, ax1 = plt. subplots(figsize=(9, 6)) # Instantiate a second axes that shares the same x-axis ax2 = ax1.
Matplotlib secondary y-axis label We can use ylabel() function or set_ylabel() function to add label at y-axis. In this example, we add a label at the secondary y-axis by using ylabel() method. Import necessary libraries such as numpy and matplotlib. pyplot.
If I understand your question right, you want to plot two things on the same axes
with no shared axis
. There is probably a better way to do this, but you can stack twinx
(doc) and twiny
(doc) as such
ax # your first axes
ax_new = ax.twinx().twiny()
Which will give you tick marks on all sides of the plot. ax
will plot against the bottom and left, ax_new
will plot against the top and right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With