Python Forum

Full Version: Plotting “simple” diagram with gridlines at specified intervals
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I’d like to plot a diagram according to the sketch in the link. The lines emanating from the y-axis should be dotted, and the boxes above the x-axis are supposed to be squares. The square enclosed by the dotted lines and the non-dotted line should be shaded. Preferably with the labels “bin j” and “bin i” as well. Is this possible to plot with specifying gridlines at specific intervals?

[Image: 3hDAEVt]

https://imgur.com/3hDAEVt
(Dec-03-2020, 11:46 AM)schniefen Wrote: [ -> ]I’d like to plot a diagram according to the sketch in the link. The lines emanating from the y-axis should be dotted, and the boxes above the x-axis are supposed to be squares. The square enclosed by the dotted lines and the non-dotted line should be shaded. Preferably with the labels “bin j” and “bin i” as well. Is this possible to plot with specifying gridlines at specific intervals?

[Image: 3hDAEVt]

https://imgur.com/3hDAEVt
import matplotlib.pyplot as plt

fig, ax= plt.subplots()
ax.plot()
ax.axvspan(0.4,0.6,ymin=0.6,ymax=0.8,alpha=0.5,color='grey')
ax.set_xlim(0,1)
ax.set_ylim(0,1)
ax.set_xlabel('x',horizontalalignment='right', x=1.0)
ax.set_ylabel('z',horizontalalignment='right', y=1.0)
ax.vlines([0.4,0.6],0,1)
ax.hlines([0.2,0.4],0.4,0.6)
ax.hlines([0.6,0.8],0,1)
ax.text(0.5, -0.1, 'bin $i$', horizontalalignment='center', verticalalignment='center', transform=ax.transAxes)
ax.text(-0.1, 0.7, 'bin $k$', horizontalalignment='center', verticalalignment='center', rotation='vertical', transform=ax.transAxes);