Feb-06-2017, 05:56 PM
Hi all,
I wrote a function which plots rectangles filled or not. If I use flag == 0 I want rectangles filled, in case of flag == 1 I want only the contour of the rectangles. Here's my function:
At this moment my code produces two figures as you can see below, but the perfect result is the combination of both:
![[Image: ndYeZ9qPJVs8DdtH8]](https://goo.gl/photos/ndYeZ9qPJVs8DdtH8)
I wrote a function which plots rectangles filled or not. If I use flag == 0 I want rectangles filled, in case of flag == 1 I want only the contour of the rectangles. Here's my function:
#!/usr/bin/env python3 import numpy as np import matplotlib.pyplot as plt import matplotlib #from matplotlib.patches import Polygon #from matplotlib.collections import PatchCollection def tabular(X,dx,p,prism,flag): vm=3*max(p[:,4]) fig = plt.figure() ax = fig.add_subplot(111) for i in range(prism): xl = (p[i,2]-p[i,3]/2) cor='red' if p[i,1] < 0: cor='blue' if flag == 0: rect = matplotlib.patches.Rectangle((xl,p[i,4]), p[i,3], vm-p[i,4], color=cor) ax.add_patch(rect) plt.xlim(X[0], X[-1]) plt.ylim([0, vm]) ax = plt.gca() ax.invert_yaxis() elif flag == 1: rect = matplotlib.patches.Rectangle((xl,p[i,4]), p[i,3], vm-p[i,4], linestyle = '--', fill = False) ax.add_patch(rect) plt.xlim(X[0], X[-1]) plt.ylim([0, vm]) ax = plt.gca() ax.invert_yaxis() plt.title('Disposição de Prismas') plt.xlabel('Posição(m)') plt.ylabel('Profundidade (m)') plt.show() returnThe function works well. But, I want to call it two times. In the first one, I need to plot color rectangles. In the second one, I want to change the arguments and plot the results, only with the contour, in the same figure. The final result needs to be a single figure with colorful and contour rectangles. A superscription similar to the function 'hold on' from Matlab is that what I want.
At this moment my code produces two figures as you can see below, but the perfect result is the combination of both: