<div dir="ltr"><div><div>Hi Ekrem,<br><br></div>From the sounds of it, you're creating a stratigraphic column.  It sounds you already have numerical values that correspond to lithology (or something similar).<br><br>There's more than one way to approach this problem. Which way is best will depend on what you're doing, but here's one example. <br></div><div><div><div><div><span style="font-family:monospace,monospace"></span><div style="margin-left:40px"><span style="font-family:monospace,monospace"><br>import numpy as np<br>import matplotlib.pyplot as plt<br>from matplotlib.colors import from_levels_and_colors<br><br># Tops and base of section (7 values)<br>tops = np.array([780, 820, 850, 900, 910, 1000])<br><br># Lithology in each interval (6 values)<br>lith = np.array([1, 3, 2, 3, 2, 1])<br><br># Left and right x-location of strat column<br>x = np.array([0, 20])<br><br># Set up a colormap and normalization instance to tie the intervals:<br># [1, 2) -> lightblue<br># [2, 3) -> yellow<br># [3, 4) -> brown<br>cmap, norm = from_levels_and_colors([1, 2, 3, 4],<br>                                    ['lightblue', 'yellow', 'saddlebrown'])<br><br># Set up the figure with one axes<br>fig, ax = plt.subplots()<br><br># We'll need the x, y, and z arrays to be 2D to use them with pcolor/pcolormesh.<br># Currently, they're 1D.  Therefore, we'll add an axis to each by slicing with<br># None.  Also, we'll use the colormap and norm we created earlier.<br>ax.pcolormesh(x[None,:], tops[:,None], lith[:,None], cmap=cmap, norm=norm)<br><br># Optional, but to approriate for this situation...<br>ax.set(xticks=[], title='Stratigraphic Section', ylabel='Depth (m)', aspect=1)<br>ax.invert_yaxis()<br>ax.margins(0)<br><br>plt.show()</span><br></div><br><img src="cid:ii_ihplp0990_151659698f093750" height="422" width="562"><br><br></div><div>A key portion to understand is how matplotlib handles colormaps.  Colormaps take a scaled, 0 to 1 range and convert it to a color.  Scaling the "raw" data to a 0 to 1 range is handled by a `<span style="font-family:monospace,monospace">Normalize</span>` instance (by default, it just scales from the min of the data to the max).  Because we want to link specific values to specific colors, we'll need both a norm and a colormap.  Fortunately, there's a function that creates both given a set of levels and colors: `<span style="font-family:monospace,monospace">matplotlib.colors.from_levels_and_colors</span>`.<br></div><div> <br>I'm using `<span style="font-family:monospace,monospace">pcolormesh</span>` to plot the individual rectangles that make up the stratigraphic section.  If you need more flexibility (e.g. a different width for each lithology), you could iterate over each interval and plot an individual rectangle.  However, for the example you described, `<span style="font-family:monospace,monospace">pcolormesh</span>` is a good fit.  <br><br>The part of this that's the hardest to understand is converting the 1D arrays to 2D for pcolormesh.  `pcolormesh` expects the input x, y, z arrays to be 2D.  We could tile (repeat) the arrays, but in this case it's easiest to add an extra "singleton" dimension by slicing with `None`.  This winds up having the same effect as tiling the arrays when the arrays are "broadcast" together.  If you're having trouble understanding this part (and how it relates to the corners of the quadrilaterals that `pcolormesh` makes), I'd be happy to show some more examples.  <br><br></div><div>Hope that helps a bit, at any rate.<br></div><div>-Joe<br></div><div><br></div><div>​<br></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 1, 2015 at 11:00 AM, Ekrem _ <span dir="ltr"><<a href="mailto:ekrem1982@hotmail.com" target="_blank">ekrem1982@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Hi.My name is Ekrem,Geophysicist.I have a question that about matplotlib.What is your suggestion about matplotlib codes?I think  that explanation as schematic is very understandable.That;</p>
<p><br>
</p>
<p><img size="81120" style="max-width:99.9%" src="cid:d2eac852-e27c-4cd7-8e47-5f81ec66fe02"><br>
</p>
<p><br>
</p>
<p>very thanks for your suggestion code </p>
<p><br>
</p>
<p><br>
</p>
</div>
</div>

<br>_______________________________________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/matplotlib-users</a><br>
<br></blockquote></div><br></div>