1#!/usr/bin/env python 2 3# Copyright (C) 2008-2016 Alan W. Irwin 4# 5# This file is part of PLplot. 6# 7# PLplot is free software; you can redistribute it and/or modify 8# it under the terms of the GNU Library General Public License as published 9# by the Free Software Foundation; version 2 of the License. 10# 11# PLplot is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU Library General Public License for more details. 15# 16# You should have received a copy of the GNU Library General Public License 17# along with the file PLplot; if not, write to the Free Software 18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 20 21# Generate PLplot logo. 22 23# Append to effective python path so that can find plplot modules. 24from plplot_python_start import * 25 26import sys 27import plplot as w 28 29# Parse and process command line arguments 30w.plparseopts(sys.argv, w.PL_PARSE_FULL) 31 32# Initialize plplot 33w.plinit() 34 35from numpy import * 36 37# Data points in x 38XPTS = 35 39# Data points in 40YPTS = 46 41 42alt = 60.0 43az = 30.0 44# Routine for defining a specific color map 1 in HLS space. 45# if gray is true, use basic grayscale variation from half-dark to light. 46# otherwise use false color variation from blue (240 deg) to red (360 deg). 47def cmap1_init(w, gray): 48 # Independent variable of control points. 49 i = array((0., 1.)) 50 if gray: 51 # Hue for control points. Doesn't matter since saturation is zero. 52 h = array((0., 0.)) 53 # Lightness ranging from half-dark (for interest) to light. 54 l = array((0.5, 1.)) 55 # Gray scale has zero saturation 56 s = array((0., 0.)) 57 else: 58 # Hue ranges from blue (240 deg) to red (0 or 360 deg) 59 h = array((240., 0.)) 60 # Lightness and saturation are constant (values taken from C example). 61 l = array((0.6, 0.6)) 62 s = array((0.8, 0.8)) 63 64 # number of cmap1 colours is 256 in this case. 65 w.plscmap1n(256) 66 # Interpolate between control points to set up cmap1. 67 w.plscmap1l(0, i, h, l, s) 68 69def main(w): 70 71 x = (arange(XPTS) - (XPTS / 2)) / float(XPTS / 2) 72 y = (arange(YPTS) - (YPTS / 2)) / float(YPTS / 2) 73 x = 1.5*x 74 y = 0.5 + y 75 x.shape = (-1,1) 76 r2 = (x*x) + (y*y) 77 z = (1. - x)*(1. - x) + 100 * (x*x - y)*(x*x - y) 78 # The log argument may be zero for just the right grid. */ 79 z = log(choose(greater(z,0.), (exp(-5.), z))) 80 81 x.shape = (-1,) 82 zmin = min(z.flat) 83 zmax = max(z.flat) 84 nlevel = 10 85 step = (zmax-zmin)/(nlevel+1) 86 clevel = zmin + step + arange(nlevel)*step 87 w.plschr(0., 1.8) 88 w.plwidth(1) 89 w.pladv(0) 90 w.plvpor(0.0, 1.0, 0.0, 1.0) 91 w.plwind(-0.43, 0.840, 0.05, 0.48) 92 w.plcol0(1) 93 w.plw3d(1.0, 1.0, 1.0, -1.5, 1.5, -0.5, 1.5, zmin, zmax, 94 alt, az) 95 w.plbox3("bnstu", "", 0.0, 0, 96 "bnstu", "", 0.0, 0, 97 "bcdmnstuv", "", 0.0, 0) 98 # If converting the -dev svg result later with the ImageMagick 99 # "convert" application or viewing the svg result with the ImageMagick 100 # "display" application must compensate for the librsvg-2.22 101 # positioning bug since librsvg is what ImageMagick uses 102 # to interpret SVG results. 103 if_rsvg_bug = True 104 if if_rsvg_bug: 105 shift = 1.00 106 else: 107 shift = 1.07 108 w.plmtex3("zs", 5.0, shift, 1.0, "z axis") 109 110 w.plcol0(2) 111 # magnitude colored plot with faceted squares 112 cmap1_init(w, 0) 113 w.plsurf3d(x, y, z, w.MAG_COLOR | w.FACETED, ()) 114 115 # Shading to provide a good background for legend. 116 x1 = 0.10 117 x2 = 0.8 118 w.plvpor(0.0, 1.0, 0.0, 1.0) 119 w.plwind(0.0, 1.0, 0.0, 1.0) 120 # Completely opaque from 0. to x1 121 w.plscol0a(15, 0, 0, 0, 1.0) 122 w.plcol0(15) 123 x=array([0., 0., x1, x1]) 124 y=array([0., 1., 1., 0.]) 125 w.plfill(x,y) 126 # Black transparent gradient. 127 pos = array([0.0, 1.0]) 128 rcoord = array([0.0, 0.0]) 129 gcoord = array([0.0, 0.0]) 130 bcoord = array([0.0, 0.0]) 131 acoord = array([1.0, 0.0]) 132 rev = array([0, 0]) 133 w.plscmap1n(2) 134 w.plscmap1la(1, pos, rcoord, gcoord, bcoord, acoord, rev) 135 x=array([x1, x1, x2, x2]) 136 w.plgradient(x,y,0.) 137 # Logo Legend 138 w.plscol0a(15, 255, 255, 255, 1.0) 139 w.plcol0(15) 140 x1 = 0.03 141 w.plschr(0., 2.9) 142 w.plsfont(w.PL_FCI_SANS, w.PL_FCI_UPRIGHT, w.PL_FCI_BOLD) 143 w.plptex(x1, 0.57, 1.0, 0.0, 0.0, "PLplot") 144 w.plschr(0., 1.5) 145 w.plptex(x1, 0.30, 1.0, 0.0, 0.0, 146 "The ultimate in cross-platform plotting") 147 148main(w) 149# Terminate plplot 150w.plend() 151