Visibility for twinx grid linesHow can I do a line break (line continuation) in Python?How to get line count cheaply in Python?How to read a file line-by-line into a list?Secondary axis with twinx(): how to add to legend?Correct way to write line to file?Catch multiple exceptions in one line (except block)Why is reading lines from stdin much slower in C++ than Python?Pythonic way to create a long multi-line stringHow to plot date range with vlines in matplotlib?vertical colored lines on a slider matplotlib
Why are Gatwick's runways too close together?
Can I not use QM-AM inequality to solve this?
is this F 6'9 chord a figured bass or a chord extension?
Why I have higher ping to the VLAN interface than to other local interfaces
Annotating a table with arrows
How can Radagast come across Gandalf and Thorin's company?
Halting problem in EXP-complete
The cat ate your input again!
What does the phrase "pull off sick wheelies and flips" mean here?
Backpack size in between small in medium, which is preferable?
On math looking obvious in retrospect
TEMPO: play a (mp3) sound in animated GIF/PDF/SVG
Am I overreacting to my team leader's unethical requests?
How to take the beginning and end parts of a list with simpler syntax?
How many people would you need to pull a whale over cobblestone streets?
How to mark beverage cans in a cooler for a blind person?
A Word/Phrase for the Process of Classifying Something as a Sin
How to render "If I have told you once, I have told you a thousand times" into French
Is this curved text blend possible in Illustrator?
If "more guns less crime", how do gun advocates explain that the EU has less crime than the US?
First amendment and employment: Can a police department terminate an officer for speech?
How to assign many blockers at the same time?
How to reduce Sinas Chinam
Visa National - No Exit Stamp From France on Return to the UK
Visibility for twinx grid lines
How can I do a line break (line continuation) in Python?How to get line count cheaply in Python?How to read a file line-by-line into a list?Secondary axis with twinx(): how to add to legend?Correct way to write line to file?Catch multiple exceptions in one line (except block)Why is reading lines from stdin much slower in C++ than Python?Pythonic way to create a long multi-line stringHow to plot date range with vlines in matplotlib?vertical colored lines on a slider matplotlib
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
When creating overlaid bar charts with two different height scales using Axes.twinx(), I cannot set visible the vertical grid lines of the 'twin' axis set. The horizontal lines work fine though. Any thoughts on how to resolve this?
Below is some example code that illustrates what I want to do and what I cannot do. As seen, the vertical grid lines are hidden by the red bars of ax2, whereas I want the grid lines to be visible through all bars.
# Create figure and figure layout
ax1 = plt.subplot()
ax2 = ax1.twinx()
# Example data
x = [0, 1, 2, 3, 4, 5]
h1 = [55, 63, 70, 84, 73, 93]
h2 = [4, 5, 4, 7, 4, 3]
# Plot bars
h1_bars = ax1.bar(x, h1, width=0.6, color='darkblue')
h2_bars = ax2.bar(x, h2, width=0.6, color='darkred')
# Set y limits and grid visibility
for ax, ylim in zip([ax1, ax2], [100, 10]):
ax.set_ylim(0, ylim)
ax.grid(True)

The error comes about because the vertical grid lines of ax2 are not set visible. This can be tested by setting ax1.grid(False), in which case there are only horizontal grid lines.

I have tried all combinations of ax1.xaxis.grid(True), ax1.yaxis.grid(True), ax2.xaxis.grid(True) and ax2.yaxis.grid(True) without any luck. Any help on this matter deeply appreciated!
python matplotlib
add a comment |
When creating overlaid bar charts with two different height scales using Axes.twinx(), I cannot set visible the vertical grid lines of the 'twin' axis set. The horizontal lines work fine though. Any thoughts on how to resolve this?
Below is some example code that illustrates what I want to do and what I cannot do. As seen, the vertical grid lines are hidden by the red bars of ax2, whereas I want the grid lines to be visible through all bars.
# Create figure and figure layout
ax1 = plt.subplot()
ax2 = ax1.twinx()
# Example data
x = [0, 1, 2, 3, 4, 5]
h1 = [55, 63, 70, 84, 73, 93]
h2 = [4, 5, 4, 7, 4, 3]
# Plot bars
h1_bars = ax1.bar(x, h1, width=0.6, color='darkblue')
h2_bars = ax2.bar(x, h2, width=0.6, color='darkred')
# Set y limits and grid visibility
for ax, ylim in zip([ax1, ax2], [100, 10]):
ax.set_ylim(0, ylim)
ax.grid(True)

The error comes about because the vertical grid lines of ax2 are not set visible. This can be tested by setting ax1.grid(False), in which case there are only horizontal grid lines.

I have tried all combinations of ax1.xaxis.grid(True), ax1.yaxis.grid(True), ax2.xaxis.grid(True) and ax2.yaxis.grid(True) without any luck. Any help on this matter deeply appreciated!
python matplotlib
Ok, obviously one workaround is to scale theh2-data with they-axii ratio (10 in this case) and then ploth2inax1like this:h2_bars = ax1.bar(x, [10*h for h in h2], width=0.6, color='darkred').
– Robert
Mar 27 at 9:08
1
Usually the grid lines are below patches. But you can setax.set_axisbelow(False)to have them appear in front.
– ImportanceOfBeingErnest
Mar 27 at 11:43
Thanks @ImportanceOfBeingErnest. I actually already tried that. It does not work because there are no vertical grid lines inax2to begin with, so they cannot be brought to the front.
– Robert
Mar 27 at 14:25
1
Oh, sorry, I think I misunderstood the problem. Indeed,ax2does not have any grid lines.
– ImportanceOfBeingErnest
Mar 27 at 14:57
add a comment |
When creating overlaid bar charts with two different height scales using Axes.twinx(), I cannot set visible the vertical grid lines of the 'twin' axis set. The horizontal lines work fine though. Any thoughts on how to resolve this?
Below is some example code that illustrates what I want to do and what I cannot do. As seen, the vertical grid lines are hidden by the red bars of ax2, whereas I want the grid lines to be visible through all bars.
# Create figure and figure layout
ax1 = plt.subplot()
ax2 = ax1.twinx()
# Example data
x = [0, 1, 2, 3, 4, 5]
h1 = [55, 63, 70, 84, 73, 93]
h2 = [4, 5, 4, 7, 4, 3]
# Plot bars
h1_bars = ax1.bar(x, h1, width=0.6, color='darkblue')
h2_bars = ax2.bar(x, h2, width=0.6, color='darkred')
# Set y limits and grid visibility
for ax, ylim in zip([ax1, ax2], [100, 10]):
ax.set_ylim(0, ylim)
ax.grid(True)

The error comes about because the vertical grid lines of ax2 are not set visible. This can be tested by setting ax1.grid(False), in which case there are only horizontal grid lines.

I have tried all combinations of ax1.xaxis.grid(True), ax1.yaxis.grid(True), ax2.xaxis.grid(True) and ax2.yaxis.grid(True) without any luck. Any help on this matter deeply appreciated!
python matplotlib
When creating overlaid bar charts with two different height scales using Axes.twinx(), I cannot set visible the vertical grid lines of the 'twin' axis set. The horizontal lines work fine though. Any thoughts on how to resolve this?
Below is some example code that illustrates what I want to do and what I cannot do. As seen, the vertical grid lines are hidden by the red bars of ax2, whereas I want the grid lines to be visible through all bars.
# Create figure and figure layout
ax1 = plt.subplot()
ax2 = ax1.twinx()
# Example data
x = [0, 1, 2, 3, 4, 5]
h1 = [55, 63, 70, 84, 73, 93]
h2 = [4, 5, 4, 7, 4, 3]
# Plot bars
h1_bars = ax1.bar(x, h1, width=0.6, color='darkblue')
h2_bars = ax2.bar(x, h2, width=0.6, color='darkred')
# Set y limits and grid visibility
for ax, ylim in zip([ax1, ax2], [100, 10]):
ax.set_ylim(0, ylim)
ax.grid(True)

The error comes about because the vertical grid lines of ax2 are not set visible. This can be tested by setting ax1.grid(False), in which case there are only horizontal grid lines.

I have tried all combinations of ax1.xaxis.grid(True), ax1.yaxis.grid(True), ax2.xaxis.grid(True) and ax2.yaxis.grid(True) without any luck. Any help on this matter deeply appreciated!
python matplotlib
python matplotlib
edited Mar 27 at 9:03
Robert
asked Mar 27 at 8:52
RobertRobert
477 bronze badges
477 bronze badges
Ok, obviously one workaround is to scale theh2-data with they-axii ratio (10 in this case) and then ploth2inax1like this:h2_bars = ax1.bar(x, [10*h for h in h2], width=0.6, color='darkred').
– Robert
Mar 27 at 9:08
1
Usually the grid lines are below patches. But you can setax.set_axisbelow(False)to have them appear in front.
– ImportanceOfBeingErnest
Mar 27 at 11:43
Thanks @ImportanceOfBeingErnest. I actually already tried that. It does not work because there are no vertical grid lines inax2to begin with, so they cannot be brought to the front.
– Robert
Mar 27 at 14:25
1
Oh, sorry, I think I misunderstood the problem. Indeed,ax2does not have any grid lines.
– ImportanceOfBeingErnest
Mar 27 at 14:57
add a comment |
Ok, obviously one workaround is to scale theh2-data with they-axii ratio (10 in this case) and then ploth2inax1like this:h2_bars = ax1.bar(x, [10*h for h in h2], width=0.6, color='darkred').
– Robert
Mar 27 at 9:08
1
Usually the grid lines are below patches. But you can setax.set_axisbelow(False)to have them appear in front.
– ImportanceOfBeingErnest
Mar 27 at 11:43
Thanks @ImportanceOfBeingErnest. I actually already tried that. It does not work because there are no vertical grid lines inax2to begin with, so they cannot be brought to the front.
– Robert
Mar 27 at 14:25
1
Oh, sorry, I think I misunderstood the problem. Indeed,ax2does not have any grid lines.
– ImportanceOfBeingErnest
Mar 27 at 14:57
Ok, obviously one workaround is to scale the
h2-data with the y-axii ratio (10 in this case) and then plot h2 in ax1 like this: h2_bars = ax1.bar(x, [10*h for h in h2], width=0.6, color='darkred').– Robert
Mar 27 at 9:08
Ok, obviously one workaround is to scale the
h2-data with the y-axii ratio (10 in this case) and then plot h2 in ax1 like this: h2_bars = ax1.bar(x, [10*h for h in h2], width=0.6, color='darkred').– Robert
Mar 27 at 9:08
1
1
Usually the grid lines are below patches. But you can set
ax.set_axisbelow(False) to have them appear in front.– ImportanceOfBeingErnest
Mar 27 at 11:43
Usually the grid lines are below patches. But you can set
ax.set_axisbelow(False) to have them appear in front.– ImportanceOfBeingErnest
Mar 27 at 11:43
Thanks @ImportanceOfBeingErnest. I actually already tried that. It does not work because there are no vertical grid lines in
ax2 to begin with, so they cannot be brought to the front.– Robert
Mar 27 at 14:25
Thanks @ImportanceOfBeingErnest. I actually already tried that. It does not work because there are no vertical grid lines in
ax2 to begin with, so they cannot be brought to the front.– Robert
Mar 27 at 14:25
1
1
Oh, sorry, I think I misunderstood the problem. Indeed,
ax2 does not have any grid lines.– ImportanceOfBeingErnest
Mar 27 at 14:57
Oh, sorry, I think I misunderstood the problem. Indeed,
ax2 does not have any grid lines.– ImportanceOfBeingErnest
Mar 27 at 14:57
add a comment |
1 Answer
1
active
oldest
votes
You may revert the role of ax1 and ax2, such that the blue bars are on ax2 and the red ones on ax1. Then you need to put the twin axes in the background and tick the respective y axes on the other side of the plot.
import matplotlib.pyplot as plt
# Create figure and figure layout
ax1 = plt.subplot()
ax2 = ax1.twinx()
# Example data
x = [0, 1, 2, 3, 4, 5]
h1 = [55, 63, 70, 84, 73, 93]
h2 = [4, 5, 4, 7, 4, 3]
# Plot bars
h1_bars = ax2.bar(x, h1, width=0.6, color='darkblue')
h2_bars = ax1.bar(x, h2, width=0.6, color='darkred')
# Set y limits and grid visibility
for ax, ylim in zip([ax1, ax2], [10, 100]):
ax.set_ylim(0, ylim)
ax.grid(True)
ax1.set_zorder(1)
ax1.patch.set_alpha(0)
ax2.set_zorder(0)
ax1.yaxis.tick_right()
ax2.yaxis.tick_left()
plt.show()

This is God! I tried so many ways but missed theset_alpha. +1 again
– Sheldore
Mar 27 at 16:05
@ImportanceOfBeingErnest Thanks for this workaround. It’s great, and I was also delighted to learn about set_alpha. It doesn’t answer my original question on how to make visible the grid lines of ax2, but I’ll accept it anyhow since it gets the job done.
– Robert
Mar 28 at 21:30
1
The point is,ax2does not have any vertical gridlines, because it is a twin axes. Meaning, it shares the grid and ticks withax1for the direction of the twinning.
– ImportanceOfBeingErnest
Mar 28 at 21:54
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55373097%2fvisibility-for-twinx-grid-lines%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You may revert the role of ax1 and ax2, such that the blue bars are on ax2 and the red ones on ax1. Then you need to put the twin axes in the background and tick the respective y axes on the other side of the plot.
import matplotlib.pyplot as plt
# Create figure and figure layout
ax1 = plt.subplot()
ax2 = ax1.twinx()
# Example data
x = [0, 1, 2, 3, 4, 5]
h1 = [55, 63, 70, 84, 73, 93]
h2 = [4, 5, 4, 7, 4, 3]
# Plot bars
h1_bars = ax2.bar(x, h1, width=0.6, color='darkblue')
h2_bars = ax1.bar(x, h2, width=0.6, color='darkred')
# Set y limits and grid visibility
for ax, ylim in zip([ax1, ax2], [10, 100]):
ax.set_ylim(0, ylim)
ax.grid(True)
ax1.set_zorder(1)
ax1.patch.set_alpha(0)
ax2.set_zorder(0)
ax1.yaxis.tick_right()
ax2.yaxis.tick_left()
plt.show()

This is God! I tried so many ways but missed theset_alpha. +1 again
– Sheldore
Mar 27 at 16:05
@ImportanceOfBeingErnest Thanks for this workaround. It’s great, and I was also delighted to learn about set_alpha. It doesn’t answer my original question on how to make visible the grid lines of ax2, but I’ll accept it anyhow since it gets the job done.
– Robert
Mar 28 at 21:30
1
The point is,ax2does not have any vertical gridlines, because it is a twin axes. Meaning, it shares the grid and ticks withax1for the direction of the twinning.
– ImportanceOfBeingErnest
Mar 28 at 21:54
add a comment |
You may revert the role of ax1 and ax2, such that the blue bars are on ax2 and the red ones on ax1. Then you need to put the twin axes in the background and tick the respective y axes on the other side of the plot.
import matplotlib.pyplot as plt
# Create figure and figure layout
ax1 = plt.subplot()
ax2 = ax1.twinx()
# Example data
x = [0, 1, 2, 3, 4, 5]
h1 = [55, 63, 70, 84, 73, 93]
h2 = [4, 5, 4, 7, 4, 3]
# Plot bars
h1_bars = ax2.bar(x, h1, width=0.6, color='darkblue')
h2_bars = ax1.bar(x, h2, width=0.6, color='darkred')
# Set y limits and grid visibility
for ax, ylim in zip([ax1, ax2], [10, 100]):
ax.set_ylim(0, ylim)
ax.grid(True)
ax1.set_zorder(1)
ax1.patch.set_alpha(0)
ax2.set_zorder(0)
ax1.yaxis.tick_right()
ax2.yaxis.tick_left()
plt.show()

This is God! I tried so many ways but missed theset_alpha. +1 again
– Sheldore
Mar 27 at 16:05
@ImportanceOfBeingErnest Thanks for this workaround. It’s great, and I was also delighted to learn about set_alpha. It doesn’t answer my original question on how to make visible the grid lines of ax2, but I’ll accept it anyhow since it gets the job done.
– Robert
Mar 28 at 21:30
1
The point is,ax2does not have any vertical gridlines, because it is a twin axes. Meaning, it shares the grid and ticks withax1for the direction of the twinning.
– ImportanceOfBeingErnest
Mar 28 at 21:54
add a comment |
You may revert the role of ax1 and ax2, such that the blue bars are on ax2 and the red ones on ax1. Then you need to put the twin axes in the background and tick the respective y axes on the other side of the plot.
import matplotlib.pyplot as plt
# Create figure and figure layout
ax1 = plt.subplot()
ax2 = ax1.twinx()
# Example data
x = [0, 1, 2, 3, 4, 5]
h1 = [55, 63, 70, 84, 73, 93]
h2 = [4, 5, 4, 7, 4, 3]
# Plot bars
h1_bars = ax2.bar(x, h1, width=0.6, color='darkblue')
h2_bars = ax1.bar(x, h2, width=0.6, color='darkred')
# Set y limits and grid visibility
for ax, ylim in zip([ax1, ax2], [10, 100]):
ax.set_ylim(0, ylim)
ax.grid(True)
ax1.set_zorder(1)
ax1.patch.set_alpha(0)
ax2.set_zorder(0)
ax1.yaxis.tick_right()
ax2.yaxis.tick_left()
plt.show()

You may revert the role of ax1 and ax2, such that the blue bars are on ax2 and the red ones on ax1. Then you need to put the twin axes in the background and tick the respective y axes on the other side of the plot.
import matplotlib.pyplot as plt
# Create figure and figure layout
ax1 = plt.subplot()
ax2 = ax1.twinx()
# Example data
x = [0, 1, 2, 3, 4, 5]
h1 = [55, 63, 70, 84, 73, 93]
h2 = [4, 5, 4, 7, 4, 3]
# Plot bars
h1_bars = ax2.bar(x, h1, width=0.6, color='darkblue')
h2_bars = ax1.bar(x, h2, width=0.6, color='darkred')
# Set y limits and grid visibility
for ax, ylim in zip([ax1, ax2], [10, 100]):
ax.set_ylim(0, ylim)
ax.grid(True)
ax1.set_zorder(1)
ax1.patch.set_alpha(0)
ax2.set_zorder(0)
ax1.yaxis.tick_right()
ax2.yaxis.tick_left()
plt.show()

answered Mar 27 at 14:59
ImportanceOfBeingErnestImportanceOfBeingErnest
161k15 gold badges200 silver badges291 bronze badges
161k15 gold badges200 silver badges291 bronze badges
This is God! I tried so many ways but missed theset_alpha. +1 again
– Sheldore
Mar 27 at 16:05
@ImportanceOfBeingErnest Thanks for this workaround. It’s great, and I was also delighted to learn about set_alpha. It doesn’t answer my original question on how to make visible the grid lines of ax2, but I’ll accept it anyhow since it gets the job done.
– Robert
Mar 28 at 21:30
1
The point is,ax2does not have any vertical gridlines, because it is a twin axes. Meaning, it shares the grid and ticks withax1for the direction of the twinning.
– ImportanceOfBeingErnest
Mar 28 at 21:54
add a comment |
This is God! I tried so many ways but missed theset_alpha. +1 again
– Sheldore
Mar 27 at 16:05
@ImportanceOfBeingErnest Thanks for this workaround. It’s great, and I was also delighted to learn about set_alpha. It doesn’t answer my original question on how to make visible the grid lines of ax2, but I’ll accept it anyhow since it gets the job done.
– Robert
Mar 28 at 21:30
1
The point is,ax2does not have any vertical gridlines, because it is a twin axes. Meaning, it shares the grid and ticks withax1for the direction of the twinning.
– ImportanceOfBeingErnest
Mar 28 at 21:54
This is God! I tried so many ways but missed the
set_alpha. +1 again– Sheldore
Mar 27 at 16:05
This is God! I tried so many ways but missed the
set_alpha. +1 again– Sheldore
Mar 27 at 16:05
@ImportanceOfBeingErnest Thanks for this workaround. It’s great, and I was also delighted to learn about set_alpha. It doesn’t answer my original question on how to make visible the grid lines of ax2, but I’ll accept it anyhow since it gets the job done.
– Robert
Mar 28 at 21:30
@ImportanceOfBeingErnest Thanks for this workaround. It’s great, and I was also delighted to learn about set_alpha. It doesn’t answer my original question on how to make visible the grid lines of ax2, but I’ll accept it anyhow since it gets the job done.
– Robert
Mar 28 at 21:30
1
1
The point is,
ax2 does not have any vertical gridlines, because it is a twin axes. Meaning, it shares the grid and ticks with ax1 for the direction of the twinning.– ImportanceOfBeingErnest
Mar 28 at 21:54
The point is,
ax2 does not have any vertical gridlines, because it is a twin axes. Meaning, it shares the grid and ticks with ax1 for the direction of the twinning.– ImportanceOfBeingErnest
Mar 28 at 21:54
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55373097%2fvisibility-for-twinx-grid-lines%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Ok, obviously one workaround is to scale the
h2-data with they-axii ratio (10 in this case) and then ploth2inax1like this:h2_bars = ax1.bar(x, [10*h for h in h2], width=0.6, color='darkred').– Robert
Mar 27 at 9:08
1
Usually the grid lines are below patches. But you can set
ax.set_axisbelow(False)to have them appear in front.– ImportanceOfBeingErnest
Mar 27 at 11:43
Thanks @ImportanceOfBeingErnest. I actually already tried that. It does not work because there are no vertical grid lines in
ax2to begin with, so they cannot be brought to the front.– Robert
Mar 27 at 14:25
1
Oh, sorry, I think I misunderstood the problem. Indeed,
ax2does not have any grid lines.– ImportanceOfBeingErnest
Mar 27 at 14:57