Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Maybe it is a bit crude to answer my own question, but I would like to share what I could find so far. This version can color two subplots with axes <code>[ax1, ax2]</code> and <code>[ax3, ax4]</code> in two different colors. It is <em>much</em> shorter than the 16 lines I stated in my question above. It is inspired by Joe Kington's answer here and in <a href="https://stackoverflow.com/questions/7779164/twinx-kills-tick-label-color/7787535#7787535">twinx kills tick label color</a>.</p> <pre><code>import matplotlib.pyplot as plt import numpy as np # Generate some data num = 200 x = np.linspace(501, 1200, num) yellow_data, green_data , blue_data= np.random.random((3,num)) green_data += np.linspace(0, 3, yellow_data.size)/2 blue_data += np.linspace(0, 3, yellow_data.size)/2 fig = plt.figure() plt.subplot(211) # Upper Plot ax1 = fig.add_subplot(211) ax1.fill_between(x, 0, yellow_data, color='yellow') ax2 = ax1.twinx() ax2.plot(x, green_data, 'green') plt.setp(plt.gca(), xticklabels=[]) plt.subplot(212) # Lower Plot ax3 = fig.add_subplot(212) ax3.fill_between(x, 0, yellow_data, color='yellow') ax4 = ax3.twinx() ax4.plot(x, blue_data, 'blue') # Start coloring for ax, color in zip([ax1, ax2, ax3, ax4], ['green', 'green', 'blue', 'blue']): for ticks in ax.xaxis.get_ticklines() + ax.yaxis.get_ticklines(): ticks.set_color(color) for pos in ['top', 'bottom', 'right', 'left']: ax.spines[pos].set_edgecolor(color) # End coloring plt.show() </code></pre> <p><img src="https://i.stack.imgur.com/jgB20.png" alt="color_plots"></p> <p>I marked this as accepted since it's the most compact solution that I could find so far. Still, I am open for other, maybe more elegant ways to solve it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload