mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
update 3D particles render
This commit is contained in:
parent
2fc98dbb02
commit
7423d8dfb9
@ -8317,4 +8317,126 @@ public class GraphicFactory {
|
||||
return graphics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create particle graphics
|
||||
*
|
||||
* @param data 3d data array
|
||||
* @param xa X coordinates
|
||||
* @param ya Y coordinates
|
||||
* @param za Z coordinates
|
||||
* @param ls LegendScheme
|
||||
* @param alphaMin Min alpha
|
||||
* @param alphaMax Max alpha
|
||||
* @param density Point density
|
||||
* @return Particles
|
||||
*/
|
||||
public static GraphicCollection particles(Array data, Array xa, Array ya, Array za, LegendScheme ls,
|
||||
float alphaMin, float alphaMax, int density) {
|
||||
data = data.copyIfView();
|
||||
xa = xa.copyIfView();
|
||||
ya = ya.copyIfView();
|
||||
za = za.copyIfView();
|
||||
|
||||
ParticleGraphics graphics = new ParticleGraphics();
|
||||
ParticleGraphics.Particle particle;
|
||||
Random random = new Random();
|
||||
float dx = xa.getFloat(1) - xa.getFloat(0);
|
||||
float dy = ya.getFloat(1) - ya.getFloat(0);
|
||||
float dz = za.getFloat(1) - za.getFloat(0);
|
||||
int n = ls.getBreakNum();
|
||||
float[] alphas = new float[n];
|
||||
float dd = (alphaMax - alphaMin) / (n - 1);
|
||||
for (int i = 0; i < n; i++) {
|
||||
alphas[i] = alphaMin + i * dd;
|
||||
}
|
||||
double v;
|
||||
ColorBreak cb;
|
||||
float[] rgba;
|
||||
int level;
|
||||
double vMin = ls.getMinValue();
|
||||
double vMax = ls.getMaxValue();
|
||||
Index index = data.getIndex();
|
||||
if (za.getRank() == 1) {
|
||||
for (int i = 0; i < za.getSize(); i++) {
|
||||
for (int j = 0; j < ya.getSize(); j++) {
|
||||
for (int k = 0; k < xa.getSize(); k++) {
|
||||
index.set(i, j, k);
|
||||
v = data.getDouble(index);
|
||||
if (Double.isNaN(v)) {
|
||||
continue;
|
||||
}
|
||||
if (v < vMin || v > vMax) {
|
||||
continue;
|
||||
}
|
||||
level = ls.legendBreakIndex(v);
|
||||
if (level >= 0) {
|
||||
cb = ls.getLegendBreak(level);
|
||||
rgba = cb.getColor().getRGBComponents(null);
|
||||
rgba[3] = alphas[level];
|
||||
for (int l = 0; l <= level * density; l++) {
|
||||
particle = new ParticleGraphics.Particle();
|
||||
particle.x = xa.getFloat(k) + (random.nextFloat() - 0.5f) * dx * 2;
|
||||
particle.y = ya.getFloat(j) + (random.nextFloat() - 0.5f) * dy * 2;
|
||||
particle.z = za.getFloat(i) + (random.nextFloat() - 0.5f) * dz * 2;
|
||||
particle.rgba = rgba;
|
||||
graphics.addParticle(level, particle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int zn = za.getShape()[0];
|
||||
Index zIndex = za.getIndex();
|
||||
float z;
|
||||
for (int i = 0; i < zn; i++) {
|
||||
for (int j = 0; j < ya.getSize(); j++) {
|
||||
for (int k = 0; k < xa.getSize(); k++) {
|
||||
index.set(i, j, k);
|
||||
v = data.getDouble(index);
|
||||
if (Double.isNaN(v)) {
|
||||
continue;
|
||||
}
|
||||
if (v < vMin || v > vMax) {
|
||||
continue;
|
||||
}
|
||||
level = ls.legendBreakIndex(v);
|
||||
zIndex.set(i, j, k);
|
||||
z = za.getFloat(zIndex);
|
||||
if (i == 0)
|
||||
zIndex.set(1, j, k);
|
||||
else
|
||||
zIndex.set(i - 1, j, k);
|
||||
dz = Math.abs(z - za.getFloat(zIndex));
|
||||
if (level >= 0) {
|
||||
cb = ls.getLegendBreak(level);
|
||||
rgba = cb.getColor().getRGBComponents(null);
|
||||
rgba[3] = alphas[level];
|
||||
for (int l = 0; l <= level * density; l++) {
|
||||
particle = new ParticleGraphics.Particle();
|
||||
particle.x = xa.getFloat(k) + (random.nextFloat() - 0.5f) * dx * 2;
|
||||
particle.y = ya.getFloat(j) + (random.nextFloat() - 0.5f) * dy * 2;
|
||||
particle.z = z + (random.nextFloat() - 0.5f) * dz * 2;
|
||||
particle.rgba = rgba;
|
||||
graphics.addParticle(level, particle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Extent3D extent3D = new Extent3D();
|
||||
extent3D.minX = xa.getDouble(0);
|
||||
extent3D.maxX = xa.getDouble((int) xa.getSize() - 1);
|
||||
extent3D.minY = ya.getDouble(0);
|
||||
extent3D.maxY = ya.getDouble((int) ya.getSize() - 1);
|
||||
extent3D.minZ = za.getDouble(0);
|
||||
extent3D.maxZ = za.getDouble((int) za.getSize() - 1);
|
||||
graphics.setExtent(extent3D);
|
||||
graphics.setLegendScheme(ls);
|
||||
|
||||
return graphics;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -70,6 +70,19 @@ public class ParticleGraphics extends GraphicCollection3D {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get point number
|
||||
* @return Point number
|
||||
*/
|
||||
public int getPointNumber() {
|
||||
int n = 0;
|
||||
for (List list : this.particles.values()) {
|
||||
n += list.size();
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sorted particle list
|
||||
* @return Particle list
|
||||
|
||||
@ -2451,10 +2451,17 @@ public class GLPlot extends Plot {
|
||||
meshRender.setLighting(this.lighting);
|
||||
meshRender.updateMatrix();
|
||||
meshRender.draw();
|
||||
} else if (graphic instanceof IsosurfaceGraphics) {
|
||||
this.drawIsosurface(gl, (IsosurfaceGraphics) graphic);
|
||||
} else if (graphic instanceof ParticleGraphics) {
|
||||
this.drawParticles(gl, (ParticleGraphics) graphic);
|
||||
//this.drawParticles(gl, (ParticleGraphics) graphic);
|
||||
if (!this.renderMap.containsKey(graphic)) {
|
||||
renderMap.put(graphic, new PointRender(gl, (GraphicCollection3D) graphic));
|
||||
}
|
||||
PointRender pointRender = (PointRender) renderMap.get(graphic);
|
||||
pointRender.setTransform(this.transform, this.alwaysUpdateBuffers);
|
||||
pointRender.setOrthographic(this.orthographic);
|
||||
pointRender.setLighting(this.lighting);
|
||||
pointRender.updateMatrix();
|
||||
pointRender.draw();
|
||||
} else if (graphic instanceof TriMeshGraphic) {
|
||||
if (!this.renderMap.containsKey(graphic)) {
|
||||
renderMap.put(graphic, new TriMeshRender(gl, (TriMeshGraphic) graphic));
|
||||
@ -2501,10 +2508,6 @@ public class GLPlot extends Plot {
|
||||
if (isDraw) {
|
||||
switch (graphic.getGraphicN(0).getShape().getShapeType()) {
|
||||
case POINT_Z:
|
||||
//if (((GraphicCollection3D) graphic).isSphere()) {
|
||||
// this.drawSpheres(gl, graphic);
|
||||
//} else {
|
||||
//this.drawPoints(gl, graphic);
|
||||
if (!this.renderMap.containsKey(graphic)) {
|
||||
renderMap.put(graphic, new PointRender(gl, (GraphicCollection3D) graphic));
|
||||
}
|
||||
@ -2514,7 +2517,6 @@ public class GLPlot extends Plot {
|
||||
pointRender.setLighting(this.lighting);
|
||||
pointRender.updateMatrix();
|
||||
pointRender.draw();
|
||||
//}
|
||||
break;
|
||||
case POLYLINE_Z:
|
||||
if (graphic.getGraphicN(0).getShape() instanceof PipeShape) {
|
||||
|
||||
@ -6,6 +6,7 @@ import com.jogamp.opengl.util.GLBuffers;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
import org.meteoinfo.chart.graphic.GraphicCollection3D;
|
||||
import org.meteoinfo.chart.graphic.ParticleGraphics;
|
||||
import org.meteoinfo.chart.graphic.sphere.Sphere;
|
||||
import org.meteoinfo.chart.jogl.Program;
|
||||
import org.meteoinfo.chart.jogl.Transform;
|
||||
@ -22,6 +23,7 @@ import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PointRender extends JOGLGraphicRender {
|
||||
|
||||
@ -69,10 +71,14 @@ public class PointRender extends JOGLGraphicRender {
|
||||
|
||||
this.graphics = pointGraphics;
|
||||
this.sphere = this.graphics.isSphere();
|
||||
if (this.graphics instanceof ParticleGraphics) {
|
||||
this.pointNum = ((ParticleGraphics) this.graphics).getPointNumber();
|
||||
this.pointSize = ((ParticleGraphics) this.graphics).getPointSize();
|
||||
} else {
|
||||
this.pointNum = pointGraphics.getNumGraphics();
|
||||
PointBreak pb = (PointBreak) this.graphics.getGraphicN(0).getLegend();
|
||||
this.pointSize = pb.getSize();
|
||||
//this.updateVertex();
|
||||
}
|
||||
}
|
||||
|
||||
void updateVertex() {
|
||||
@ -97,6 +103,15 @@ public class PointRender extends JOGLGraphicRender {
|
||||
private void updateVertexColor() {
|
||||
this.vertexColor = new float[this.pointNum * 4];
|
||||
int i = 0;
|
||||
if (this.graphics instanceof ParticleGraphics) {
|
||||
ParticleGraphics particles = (ParticleGraphics) graphics;
|
||||
for (Map.Entry<Integer, java.util.List> map : particles.getParticleList()) {
|
||||
for (ParticleGraphics.Particle p : (java.util.List<ParticleGraphics.Particle>)map.getValue()) {
|
||||
System.arraycopy(p.rgba, 0, vertexColor, i * 4, 4);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
float[] color;
|
||||
for (Graphic graphic : this.graphics.getGraphics()) {
|
||||
PointBreak pb = (PointBreak) graphic.getLegend();
|
||||
@ -105,6 +120,7 @@ public class PointRender extends JOGLGraphicRender {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateVertexPosition() {
|
||||
if (this.sphere) {
|
||||
@ -112,6 +128,17 @@ public class PointRender extends JOGLGraphicRender {
|
||||
} else {
|
||||
this.vertexPosition = new float[this.pointNum * 3];
|
||||
int i = 0;
|
||||
if (this.graphics instanceof ParticleGraphics) {
|
||||
ParticleGraphics particles = (ParticleGraphics) graphics;
|
||||
for (Map.Entry<Integer, java.util.List> map : particles.getParticleList()) {
|
||||
for (ParticleGraphics.Particle p : (java.util.List<ParticleGraphics.Particle>)map.getValue()) {
|
||||
vertexPosition[i] = transform.transform_x((float) p.x);
|
||||
vertexPosition[i + 1] = transform.transform_y((float) p.y);
|
||||
vertexPosition[i + 2] = transform.transform_z((float) p.z);
|
||||
i += 3;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (Graphic graphic : this.graphics.getGraphics()) {
|
||||
PointZShape shape = (PointZShape) graphic.getShape();
|
||||
PointZ p = (PointZ) shape.getPoint();
|
||||
@ -122,6 +149,7 @@ public class PointRender extends JOGLGraphicRender {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSphereVertex() {
|
||||
List<Vector3f> vertexPositionList = new ArrayList<>();
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<MeteoInfo File="milconfig.xml" Type="configurefile">
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\common_math\interpolate">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\math"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\new"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\others"/>
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\wind">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\test"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\scatter"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\quiver"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\3d_earth"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\interpolate"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\particles"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\wind"/>
|
||||
</Path>
|
||||
<File>
|
||||
<OpenedFiles>
|
||||
|
||||
Binary file not shown.
@ -1,9 +1,9 @@
|
||||
#-----------------------------------------------------
|
||||
# -----------------------------------------------------
|
||||
# Author: Yaqiang Wang
|
||||
# Date: 2015-12-23
|
||||
# Purpose: MeteoInfo util module
|
||||
# Note: Jython
|
||||
#-----------------------------------------------------
|
||||
# -----------------------------------------------------
|
||||
|
||||
from org.meteoinfo.common import PointD
|
||||
from org.meteoinfo.common.util import JDateUtil
|
||||
@ -16,6 +16,7 @@ from java.awt import Color
|
||||
|
||||
import datetime
|
||||
|
||||
|
||||
def pydate(t):
|
||||
"""
|
||||
Convert java date to python date.
|
||||
@ -46,6 +47,7 @@ def pydate(t):
|
||||
dt = datetime.datetime(year, month, day, hour, minute, second)
|
||||
return dt
|
||||
|
||||
|
||||
def jdate(t):
|
||||
"""
|
||||
Convert python date to java LocalDateTime.
|
||||
@ -58,14 +60,15 @@ def jdate(t):
|
||||
r = []
|
||||
for tt in t:
|
||||
t = LocalDateTime.of(tt.year, tt.month, tt.day, tt.hour, tt.minute, tt.second)
|
||||
#cal.set(Calendar.MILLISECOND, 0)
|
||||
# cal.set(Calendar.MILLISECOND, 0)
|
||||
r.append(t)
|
||||
return r
|
||||
else:
|
||||
t = LocalDateTime.of(t.year, t.month, t.day, t.hour, t.minute, t.second)
|
||||
#cal.set(Calendar.MILLISECOND, 0)
|
||||
# cal.set(Calendar.MILLISECOND, 0)
|
||||
return t
|
||||
|
||||
|
||||
def jdatetime(t):
|
||||
"""
|
||||
Convert python date to joda DateTime.
|
||||
@ -82,6 +85,7 @@ def jdatetime(t):
|
||||
else:
|
||||
return LocalDateTime.of(t.year, t.month, t.day, t.hour, t.minute, t.second, t.microsecond / 1000)
|
||||
|
||||
|
||||
def date2num(t):
|
||||
"""
|
||||
Convert python date to numerical value.
|
||||
@ -94,6 +98,7 @@ def date2num(t):
|
||||
v = JDateUtil.toOADate(tt)
|
||||
return v
|
||||
|
||||
|
||||
def dates2nums(dates):
|
||||
"""
|
||||
Convert python dates to numerical values.
|
||||
@ -108,6 +113,7 @@ def dates2nums(dates):
|
||||
values.append(JDateUtil.toOADate(tt))
|
||||
return values
|
||||
|
||||
|
||||
def num2date(v):
|
||||
"""
|
||||
Convert numerical value to python date.
|
||||
@ -119,6 +125,7 @@ def num2date(v):
|
||||
t = JDateUtil.fromOADate(v)
|
||||
return pydate(t)
|
||||
|
||||
|
||||
def nums2dates(values):
|
||||
"""
|
||||
Convert numerical values to python dates.
|
||||
@ -133,6 +140,7 @@ def nums2dates(values):
|
||||
tt.append(pydate(t))
|
||||
return tt
|
||||
|
||||
|
||||
def str2date(dstr):
|
||||
"""
|
||||
Convert string to python date.
|
||||
@ -160,6 +168,7 @@ def str2date(dstr):
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def str2jdate(dstr):
|
||||
"""
|
||||
Convert string to java date.
|
||||
@ -172,6 +181,7 @@ def str2jdate(dstr):
|
||||
jt = jdate(pt)
|
||||
return jt
|
||||
|
||||
|
||||
def str2jdatetime(dstr):
|
||||
"""
|
||||
Convert string to joda DateTime.
|
||||
@ -184,6 +194,7 @@ def str2jdatetime(dstr):
|
||||
jt = jdatetime(pt)
|
||||
return jt
|
||||
|
||||
|
||||
def dateformat(t, format, language=None):
|
||||
"""
|
||||
Format python date to string using Java date time formatter.
|
||||
@ -200,6 +211,7 @@ def dateformat(t, format, language=None):
|
||||
df = DateTimeFormatter.ofPattern(format, locale)
|
||||
return df.format(jt)
|
||||
|
||||
|
||||
def jcomplex(v):
|
||||
"""
|
||||
Convert Python complex number to Java Complex object.
|
||||
@ -210,6 +222,7 @@ def jcomplex(v):
|
||||
"""
|
||||
return Complex(v.real, v.imag)
|
||||
|
||||
|
||||
def makeshapes(x, y, type=None, z=None, m=None):
|
||||
"""
|
||||
Make shapes by x and y coordinates.
|
||||
@ -240,6 +253,7 @@ def makeshapes(x, y, type=None, z=None, m=None):
|
||||
shapes = ShapeUtil.createPolygonShapes(x, y)
|
||||
return shapes
|
||||
|
||||
|
||||
def getcolor(style, alpha=None):
|
||||
"""
|
||||
Get color.
|
||||
|
||||
Binary file not shown.
@ -5,7 +5,8 @@ from ._ndarray import NDArray
|
||||
from .dimarray import DimArray
|
||||
from org.meteoinfo.ndarray.math import ArrayUtil, ArrayMath
|
||||
|
||||
__all__ = ['cumprod','cumsum','ndim','nonzero','prod','ravel','searchsorted','sum']
|
||||
__all__ = ['cumprod', 'cumsum', 'ndim', 'nonzero', 'prod', 'ravel', 'searchsorted', 'sum']
|
||||
|
||||
|
||||
def ndim(a):
|
||||
"""
|
||||
@ -42,6 +43,7 @@ def ndim(a):
|
||||
except AttributeError:
|
||||
return asarray(a).ndim
|
||||
|
||||
|
||||
def ravel(a):
|
||||
"""
|
||||
Return a contiguous flattened array.
|
||||
@ -54,6 +56,7 @@ def ravel(a):
|
||||
|
||||
return a.ravel()
|
||||
|
||||
|
||||
def nonzero(a):
|
||||
"""
|
||||
Return the indices of the elements that are non-zero.
|
||||
@ -76,6 +79,7 @@ def nonzero(a):
|
||||
r.append(NDArray(aa))
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def searchsorted(a, v, side='left', sorter=None):
|
||||
"""
|
||||
Find indices where elements should be inserted to maintain order.
|
||||
@ -106,6 +110,7 @@ def searchsorted(a, v, side='left', sorter=None):
|
||||
else:
|
||||
return NDArray(r)
|
||||
|
||||
|
||||
def sum(x, axis=None):
|
||||
"""
|
||||
Sum of array elements over a given axis.
|
||||
@ -143,6 +148,7 @@ def sum(x, axis=None):
|
||||
dims.append(x.dims[i])
|
||||
return DimArray(NDArray(r), dims, x.fill_value, x.proj)
|
||||
|
||||
|
||||
def prod(x, axis=None):
|
||||
"""
|
||||
Product of array elements over a given axis.
|
||||
@ -170,6 +176,7 @@ def prod(x, axis=None):
|
||||
dims.append(x.dims[i])
|
||||
return DimArray(NDArray(r), dims, x.fill_value, x.proj)
|
||||
|
||||
|
||||
def cumsum(a, axis=None):
|
||||
"""
|
||||
Return the cumulative summary of elements along a given axis.
|
||||
@ -200,6 +207,7 @@ def cumsum(a, axis=None):
|
||||
dims.append(a.dims[i])
|
||||
return DimArray(r, dims, a.fill_value, a.proj)
|
||||
|
||||
|
||||
def cumprod(a, axis=None):
|
||||
"""
|
||||
Return the cumulative product of elements along a given axis.
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
# coding=utf-8
|
||||
#-----------------------------------------------------
|
||||
# -----------------------------------------------------
|
||||
# Author: Yaqiang Wang
|
||||
# Date: 2017-3-25
|
||||
# Purpose: MeteoInfoLab axes module
|
||||
# Note: Jython
|
||||
#-----------------------------------------------------
|
||||
# -----------------------------------------------------
|
||||
|
||||
from org.meteoinfo.chart import Location, ChartWindArrow, ChartText, LegendPosition, \
|
||||
ChartLegend, ChartColorBar, AspectType
|
||||
@ -35,7 +35,8 @@ import plotutil
|
||||
import colors
|
||||
import mipylib.miutil as miutil
|
||||
|
||||
__all__ = ['Axes','PolarAxes']
|
||||
__all__ = ['Axes', 'PolarAxes']
|
||||
|
||||
|
||||
class Axes(object):
|
||||
"""
|
||||
@ -430,7 +431,7 @@ class Axes(object):
|
||||
|
||||
fontname = kwargs.pop('fontname', axis.getTickLabelFont().getName())
|
||||
fontsize = kwargs.pop('fontsize', axis.getTickLabelFont().getSize())
|
||||
bold =kwargs.pop('bold', axis.getTickLabelFont().isBold())
|
||||
bold = kwargs.pop('bold', axis.getTickLabelFont().isBold())
|
||||
if bold:
|
||||
font = Font(fontname, Font.BOLD, fontsize)
|
||||
else:
|
||||
@ -482,7 +483,7 @@ class Axes(object):
|
||||
|
||||
fontname = kwargs.pop('fontname', axis.getTickLabelFont().getName())
|
||||
fontsize = kwargs.pop('fontsize', axis.getTickLabelFont().getSize())
|
||||
bold =kwargs.pop('bold', axis.getTickLabelFont().isBold())
|
||||
bold = kwargs.pop('bold', axis.getTickLabelFont().isBold())
|
||||
if bold:
|
||||
font = Font(fontname, Font.BOLD, fontsize)
|
||||
else:
|
||||
@ -563,20 +564,20 @@ class Axes(object):
|
||||
ax = self._axes
|
||||
if axistype == 'lon':
|
||||
b_axis = LonLatAxis(ax.getAxis(Location.LEFT))
|
||||
#b_axis.setLabel('Longitude')
|
||||
# b_axis.setLabel('Longitude')
|
||||
b_axis.setLongitude(True)
|
||||
ax.setAxis(b_axis, Location.LEFT)
|
||||
t_axis = LonLatAxis(ax.getAxis(Location.RIGHT))
|
||||
#t_axis.setLabel('Longitude')
|
||||
# t_axis.setLabel('Longitude')
|
||||
t_axis.setLongitude(True)
|
||||
ax.setAxis(t_axis, Location.RIGHT)
|
||||
elif axistype == 'lat':
|
||||
b_axis = LonLatAxis(ax.getAxis(Location.LEFT))
|
||||
#b_axis.setLabel('Latitude')
|
||||
# b_axis.setLabel('Latitude')
|
||||
b_axis.setLongitude(False)
|
||||
ax.setAxis(b_axis, Location.LEFT)
|
||||
t_axis = LonLatAxis(ax.getAxis(Location.RIGHT))
|
||||
#t_axis.setLabel('Latitude')
|
||||
# t_axis.setLabel('Latitude')
|
||||
t_axis.setLongitude(False)
|
||||
ax.setAxis(t_axis, Location.RIGHT)
|
||||
elif axistype == 'time':
|
||||
@ -589,11 +590,11 @@ class Axes(object):
|
||||
ax.getAxis(Location.RIGHT).setTimeFormat(timetickformat)
|
||||
elif axistype == 'log':
|
||||
l_axis = LogAxis(ax.getAxis(Location.LEFT))
|
||||
#l_axis.setLabel('Log')
|
||||
# l_axis.setLabel('Log')
|
||||
l_axis.setMinorTickNum(10)
|
||||
ax.setAxis(l_axis, Location.LEFT)
|
||||
r_axis = LogAxis(ax.getAxis(Location.RIGHT))
|
||||
#r_axis.setLabel('Log')
|
||||
# r_axis.setLabel('Log')
|
||||
r_axis.setMinorTickNum(10)
|
||||
ax.setAxis(r_axis, Location.RIGHT)
|
||||
else:
|
||||
@ -615,7 +616,7 @@ class Axes(object):
|
||||
ymax = limits[3]
|
||||
extent = Extent(xmin, xmax, ymin, ymax)
|
||||
self._axes.setDrawExtent(extent)
|
||||
#self._axes.setExtent(extent.clone())
|
||||
# self._axes.setExtent(extent.clone())
|
||||
self._axes.setFixDrawExtent(True)
|
||||
return True
|
||||
else:
|
||||
@ -1161,7 +1162,7 @@ class Axes(object):
|
||||
if ydata.ndim == 2:
|
||||
xdata = ydata.dimvalue(1)
|
||||
xx = np.zeros(ydata.shape)
|
||||
xx[:,:] = xdata
|
||||
xx[:, :] = xdata
|
||||
xdata = xx
|
||||
# if ydata.islondim(0):
|
||||
# xaxistype = 'lon'
|
||||
@ -1173,7 +1174,7 @@ class Axes(object):
|
||||
xdata = np.arange(ydata.shape[-1])
|
||||
if ydata.ndim == 2:
|
||||
xx = np.zeros(ydata.shape)
|
||||
xx[:,:] = xdata
|
||||
xx[:, :] = xdata
|
||||
xdata = xx
|
||||
xdatalist.append(xdata)
|
||||
ydatalist.append(ydata)
|
||||
@ -1185,7 +1186,7 @@ class Axes(object):
|
||||
if ydata.ndim == 2:
|
||||
xdata = ydata.dimvalue(1)
|
||||
xx = np.zeros(ydata.shape)
|
||||
xx[:,:] = xdata
|
||||
xx[:, :] = xdata
|
||||
xdata = xx
|
||||
# if ydata.islondim(0):
|
||||
# xaxistype = 'lon'
|
||||
@ -1197,7 +1198,7 @@ class Axes(object):
|
||||
xdata = np.arange(ydata.shape[-1])
|
||||
if ydata.ndim == 2:
|
||||
xx = np.zeros(ydata.shape)
|
||||
xx[:,:] = xdata
|
||||
xx[:, :] = xdata
|
||||
xdata = xx
|
||||
styles.append(args[1])
|
||||
else:
|
||||
@ -1228,7 +1229,7 @@ class Axes(object):
|
||||
while len(styles) < len(xdatalist):
|
||||
styles.append(None)
|
||||
|
||||
#Set plot data styles
|
||||
# Set plot data styles
|
||||
zvalues = kwargs.pop('zvalues', None)
|
||||
if zvalues is None:
|
||||
lines = []
|
||||
@ -1296,7 +1297,7 @@ class Axes(object):
|
||||
self._axes.getAxis(Location.BOTTOM).setTimeFormat(timetickformat)
|
||||
self._axes.getAxis(Location.TOP).setTimeFormat(timetickformat)
|
||||
|
||||
#Add graphics
|
||||
# Add graphics
|
||||
zorder = kwargs.pop('zorder', None)
|
||||
iscurve = kwargs.pop('iscurve', False)
|
||||
graphics = []
|
||||
@ -1306,7 +1307,7 @@ class Axes(object):
|
||||
graphics.append(graphic)
|
||||
else:
|
||||
if zvalues is None:
|
||||
#Add data series
|
||||
# Add data series
|
||||
snum = len(xdatalist)
|
||||
if snum == 1:
|
||||
xdata = plotutil.getplotdata(xdatalist[0])
|
||||
@ -1324,7 +1325,7 @@ class Axes(object):
|
||||
graphic = GraphicFactory.createLineString(xdata, ydata, lines, iscurve)
|
||||
else:
|
||||
graphic = GraphicFactory.createLineString(xdata, ydata, lines[0], iscurve)
|
||||
else: #>1
|
||||
else: # >1
|
||||
graphic = GraphicFactory.createLineString(xdata, ydata, lines, iscurve)
|
||||
self.add_graphic(graphic, zorder=zorder)
|
||||
graphics.append(graphic)
|
||||
@ -1375,7 +1376,7 @@ class Axes(object):
|
||||
fmt.setCaption(label)
|
||||
where = kwargs.pop('where', 'pre')
|
||||
|
||||
#Create graphics
|
||||
# Create graphics
|
||||
graphics = GraphicFactory.createStepLineString(xdata, ydata, fmt, where)
|
||||
zorder = kwargs.pop('zorder', None)
|
||||
self.add_graphic(graphics, zorder=zorder)
|
||||
@ -1410,20 +1411,20 @@ class Axes(object):
|
||||
s = kwargs.pop('s', 8)
|
||||
c = kwargs.pop('c', None)
|
||||
|
||||
#Add data series
|
||||
# Add data series
|
||||
label = kwargs.pop('label', 'S_0')
|
||||
xdata = plotutil.getplotdata(x)
|
||||
ydata = plotutil.getplotdata(y)
|
||||
|
||||
#Set plot data styles
|
||||
# Set plot data styles
|
||||
pb, isunique = plotutil.getlegendbreak('point', **kwargs)
|
||||
if c is None:
|
||||
c = pb.getColor()
|
||||
if c is None:
|
||||
c = 'b'
|
||||
pb.setCaption(label)
|
||||
#pstyle = plotutil.getpointstyle(marker)
|
||||
#pb.setStyle(pstyle)
|
||||
# pstyle = plotutil.getpointstyle(marker)
|
||||
# pb.setStyle(pstyle)
|
||||
isvalue = False
|
||||
|
||||
if isinstance(c, NDArray):
|
||||
@ -1455,7 +1456,7 @@ class Axes(object):
|
||||
n = len(s)
|
||||
for i in range(0, n):
|
||||
ls.getLegendBreaks()[i].setSize(s[i])
|
||||
#Create graphics
|
||||
# Create graphics
|
||||
graphics = GraphicFactory.createPoints(xdata, ydata, c.asarray(), ls)
|
||||
else:
|
||||
alpha = kwargs.pop('alpha', None)
|
||||
@ -1490,7 +1491,7 @@ class Axes(object):
|
||||
npb = pb.clone()
|
||||
plotutil.setpointlegendbreak(npb, **kwargs)
|
||||
pbs.append(npb)
|
||||
#Create graphics
|
||||
# Create graphics
|
||||
graphics = GraphicFactory.createPoints(xdata, ydata, pbs)
|
||||
|
||||
zorder = kwargs.pop('zorder', None)
|
||||
@ -1672,7 +1673,7 @@ class Axes(object):
|
||||
|
||||
:returns: Error bar lines.
|
||||
"""
|
||||
#Add data series
|
||||
# Add data series
|
||||
label = kwargs.pop('label', 'S_0')
|
||||
xdata = plotutil.getplotdata(x)
|
||||
ydata = plotutil.getplotdata(y)
|
||||
@ -1692,8 +1693,8 @@ class Axes(object):
|
||||
yerrB = plotutil.getplotdata(yerr[0])
|
||||
yerrU = plotutil.getplotdata(yerr[1])
|
||||
elif yerr.ndim == 2:
|
||||
yerrB = yerr[0,:].asarray()
|
||||
yerrU = yerr[1,:].asarray()
|
||||
yerrB = yerr[0, :].asarray()
|
||||
yerrU = yerr[1, :].asarray()
|
||||
else:
|
||||
yerrB = plotutil.getplotdata(yerr)
|
||||
yerrU = yerrB
|
||||
@ -1713,8 +1714,8 @@ class Axes(object):
|
||||
xerrL = plotutil.getplotdata(xerr[0])
|
||||
xerrR = plotutil.getplotdata(xerr[1])
|
||||
elif xerr.ndim == 2:
|
||||
xerrL = xerr[0,:].asarray()
|
||||
xerrR = xerr[1,:].asarray()
|
||||
xerrL = xerr[0, :].asarray()
|
||||
xerrR = xerr[1, :].asarray()
|
||||
else:
|
||||
xerrL = plotutil.getplotdata(xerr)
|
||||
xerrR = xerrL
|
||||
@ -1722,7 +1723,7 @@ class Axes(object):
|
||||
xerrL = None
|
||||
xerrR = None
|
||||
|
||||
#Get plot data style
|
||||
# Get plot data style
|
||||
if fmt == '':
|
||||
line = plotutil.getlegendbreak('line', **kwargs)[0]
|
||||
line.setCaption(label)
|
||||
@ -1740,7 +1741,7 @@ class Axes(object):
|
||||
if not elinewidth is None:
|
||||
eline.setSize(elinewidth)
|
||||
|
||||
#Create graphics
|
||||
# Create graphics
|
||||
if capsize is None:
|
||||
capsize = 10
|
||||
graphics = GraphicFactory.createErrorLineString(xdata, ydata, xerrL, xerrR, yerrB, \
|
||||
@ -1795,7 +1796,7 @@ class Axes(object):
|
||||
========= ===========
|
||||
|
||||
"""
|
||||
#Add data series
|
||||
# Add data series
|
||||
label = kwargs.pop('label', 'S_0')
|
||||
autowidth = False
|
||||
isdate = False
|
||||
@ -1817,7 +1818,7 @@ class Axes(object):
|
||||
if not bottom is None:
|
||||
bottom = plotutil.getplotdata(bottom)
|
||||
|
||||
#Set plot data styles
|
||||
# Set plot data styles
|
||||
fcobj = kwargs.pop('color', None)
|
||||
if fcobj is None:
|
||||
fcobj = kwargs.pop('facecolor', 'b')
|
||||
@ -1862,14 +1863,16 @@ class Axes(object):
|
||||
lb.setCapSize(capsize)
|
||||
barbreaks.append(lb)
|
||||
|
||||
#Create bar graphics
|
||||
# Create bar graphics
|
||||
if isinstance(width, NDArray):
|
||||
width = width.asarray()
|
||||
if morepoints:
|
||||
graphics = GraphicFactory.createBars1(x.asarray(), height.asarray(), autowidth, width, not yerr is None, yerr, \
|
||||
graphics = GraphicFactory.createBars1(x.asarray(), height.asarray(), autowidth, width, not yerr is None,
|
||||
yerr, \
|
||||
not bottom is None, bottom, barbreaks)
|
||||
else:
|
||||
graphics = GraphicFactory.createBars(x.asarray(), height.asarray(), autowidth, width, not yerr is None, yerr, \
|
||||
graphics = GraphicFactory.createBars(x.asarray(), height.asarray(), autowidth, width, not yerr is None,
|
||||
yerr, \
|
||||
not bottom is None, bottom, barbreaks)
|
||||
|
||||
zorder = kwargs.pop('zorder', None)
|
||||
@ -1921,7 +1924,7 @@ class Axes(object):
|
||||
========= ===========
|
||||
|
||||
"""
|
||||
#Add data series
|
||||
# Add data series
|
||||
label = kwargs.pop('label', 'S_0')
|
||||
xdata = None
|
||||
autoheight = True
|
||||
@ -1957,7 +1960,7 @@ class Axes(object):
|
||||
if not left is None:
|
||||
left = plotutil.getplotdata(left)
|
||||
|
||||
#Set plot data styles
|
||||
# Set plot data styles
|
||||
fcobj = kwargs.pop('color', None)
|
||||
if fcobj is None:
|
||||
fcobj = kwargs.pop('facecolor', 'b')
|
||||
@ -1995,7 +1998,7 @@ class Axes(object):
|
||||
lb.setErrorColor(ecolor)
|
||||
barbreaks.append(lb)
|
||||
|
||||
#Create bar graphics
|
||||
# Create bar graphics
|
||||
graphics = GraphicFactory.createHBars(ydata, xdata, autoheight, height, not xerr is None, xerr, \
|
||||
not left is None, left, barbreaks)
|
||||
|
||||
@ -2018,10 +2021,10 @@ class Axes(object):
|
||||
which are not required to be of the same length.
|
||||
:param bins: (*int*) If an integer is given, bins + 1 bin edges are returned.
|
||||
"""
|
||||
#Add data series
|
||||
# Add data series
|
||||
label = kwargs.pop('label', 'S_0')
|
||||
|
||||
#histogram
|
||||
# histogram
|
||||
m, bins = np.histogram(x, bins=bins, density=density)
|
||||
width = np.diff(bins)
|
||||
if cumulative:
|
||||
@ -2042,10 +2045,10 @@ class Axes(object):
|
||||
which are not required to be of the same length.
|
||||
:param bins: (*int*) If an integer is given, bins + 1 bin edges are returned.
|
||||
"""
|
||||
#Add data series
|
||||
# Add data series
|
||||
label = kwargs.pop('label', 'S_0')
|
||||
|
||||
#Set plot data styles
|
||||
# Set plot data styles
|
||||
fcobj = kwargs.pop('color', None)
|
||||
if fcobj is None:
|
||||
fcobj = kwargs.pop('facecolor', 'b')
|
||||
@ -2083,7 +2086,7 @@ class Axes(object):
|
||||
lb.setErrorColor(ecolor)
|
||||
barbreaks.append(lb)
|
||||
|
||||
#Create bar graphics
|
||||
# Create bar graphics
|
||||
x = plotutil.getplotdata(x)
|
||||
if not isinstance(bins, numbers.Number):
|
||||
bins = plotutil.getplotdata(bins)
|
||||
@ -2109,7 +2112,7 @@ class Axes(object):
|
||||
|
||||
:returns: Stem line legend break.
|
||||
"""
|
||||
#Add data series
|
||||
# Add data series
|
||||
label = kwargs.pop('label', 'S_0')
|
||||
xdata = None
|
||||
if len(args) == 1:
|
||||
@ -2126,7 +2129,7 @@ class Axes(object):
|
||||
ydata = plotutil.getplotdata(ydata)
|
||||
bottom = kwargs.pop('bottom', 0)
|
||||
|
||||
#Set plot data styles
|
||||
# Set plot data styles
|
||||
color = kwargs.pop('color', None)
|
||||
if not color is None:
|
||||
color = plotutil.getcolor(color)
|
||||
@ -2151,7 +2154,7 @@ class Axes(object):
|
||||
else:
|
||||
basefmt = plotutil.getlegendbreak('line', **basefmt)[0]
|
||||
|
||||
#Create stem graphics
|
||||
# Create stem graphics
|
||||
graphics = GraphicFactory.createStems(xdata, ydata, linefmt, markerfmt, \
|
||||
basefmt, bottom)
|
||||
|
||||
@ -2193,7 +2196,7 @@ class Axes(object):
|
||||
x = np.arange(a.shape[1])
|
||||
y = np.arange(a.shape[0])
|
||||
args = args[1:]
|
||||
elif n <=4:
|
||||
elif n <= 4:
|
||||
x = args[0]
|
||||
y = args[1]
|
||||
a = args[2]
|
||||
@ -2222,7 +2225,7 @@ class Axes(object):
|
||||
smooth = kwargs.pop('smooth', True)
|
||||
if x.ndim == 2 and y.ndim == 2:
|
||||
griddata_props = kwargs.pop('griddata_props', dict(method='idw', pointnum=5, convexhull=True))
|
||||
a, x, y = np.griddata((x,y), a, **griddata_props)
|
||||
a, x, y = np.griddata((x, y), a, **griddata_props)
|
||||
igraphic = GraphicFactory.createContourLines(x.asarray(), y.asarray(), a.asarray(), ls, smooth)
|
||||
|
||||
if not xaxistype is None:
|
||||
@ -2231,7 +2234,7 @@ class Axes(object):
|
||||
|
||||
zorder = kwargs.pop('zorder', None)
|
||||
self.add_graphic(igraphic, zorder=zorder)
|
||||
#self._axes.setAutoExtent()
|
||||
# self._axes.setAutoExtent()
|
||||
self._axes.setExtent(igraphic.getExtent())
|
||||
self._axes.setDrawExtent(igraphic.getExtent())
|
||||
|
||||
@ -2327,7 +2330,7 @@ class Axes(object):
|
||||
x = np.arange(a.shape[1])
|
||||
y = np.arange(a.shape[0])
|
||||
args = args[1:]
|
||||
elif n <=4:
|
||||
elif n <= 4:
|
||||
x = args[0]
|
||||
y = args[1]
|
||||
a = args[2]
|
||||
@ -2357,7 +2360,7 @@ class Axes(object):
|
||||
smooth = kwargs.pop('smooth', True)
|
||||
if x.ndim == 2 and y.ndim == 2:
|
||||
griddata_props = kwargs.pop('griddata_props', dict(method='idw', pointnum=5, convexhull=True))
|
||||
a, x, y = np.griddata((x,y), a, **griddata_props)
|
||||
a, x, y = np.griddata((x, y), a, **griddata_props)
|
||||
igraphic = GraphicFactory.createContourPolygons(x.asarray(), y.asarray(), a.asarray(), ls, smooth)
|
||||
|
||||
visible = kwargs.pop('visible', True)
|
||||
@ -2368,7 +2371,7 @@ class Axes(object):
|
||||
|
||||
zorder = kwargs.pop('zorder', None)
|
||||
self.add_graphic(igraphic, zorder=zorder)
|
||||
#self.setAutoExtent()
|
||||
# self.setAutoExtent()
|
||||
self._axes.setExtent(igraphic.getExtent())
|
||||
self._axes.setDrawExtent(igraphic.getExtent())
|
||||
|
||||
@ -2400,7 +2403,7 @@ class Axes(object):
|
||||
if n >= 3:
|
||||
xdata = args[0]
|
||||
ydata = args[1]
|
||||
extent = [xdata[0],xdata[-1],ydata[0],ydata[-1]]
|
||||
extent = [xdata[0], xdata[-1], ydata[0], ydata[-1]]
|
||||
args = args[2:]
|
||||
X = args[0]
|
||||
if isinstance(X, (list, tuple)):
|
||||
@ -2597,7 +2600,7 @@ class Axes(object):
|
||||
:returns: Arrow graphic.
|
||||
"""
|
||||
if not kwargs.has_key('facecolor'):
|
||||
kwargs['facecolor'] = (51,204,255)
|
||||
kwargs['facecolor'] = (51, 204, 255)
|
||||
apb, isunique = plotutil.getlegendbreak('polygon', **kwargs)
|
||||
apb = plotutil.polygon2arrow(apb, **kwargs)
|
||||
graphic = GraphicFactory.createArrow(x, y, dx, dy, apb)
|
||||
@ -2750,7 +2753,7 @@ class Axes(object):
|
||||
:param where: (*array_like*) If None, default to fill between everywhere. If not None, it is an
|
||||
N-length boolean array and the fill will only happen over the regions where ``where==True``.
|
||||
"""
|
||||
#Add data series
|
||||
# Add data series
|
||||
label = kwargs.pop('label', 'S_0')
|
||||
dn = len(x)
|
||||
xdata = plotutil.getplotdata(x)
|
||||
@ -2773,7 +2776,7 @@ class Axes(object):
|
||||
where = np.array(where)
|
||||
where = where.asarray()
|
||||
|
||||
#Set plot data styles
|
||||
# Set plot data styles
|
||||
# if not 'fill' in kwargs:
|
||||
# kwargs['fill'] = True
|
||||
# if not 'edge' in kwargs:
|
||||
@ -2781,7 +2784,7 @@ class Axes(object):
|
||||
pb, isunique = plotutil.getlegendbreak('polygon', **kwargs)
|
||||
pb.setCaption(label)
|
||||
|
||||
#Create graphics
|
||||
# Create graphics
|
||||
graphics = GraphicFactory.createFillBetweenPolygons(xdata, y1, y2, where, pb)
|
||||
zorder = kwargs.pop('zorder', None)
|
||||
self.add_graphic(graphics, zorder=zorder)
|
||||
@ -2799,7 +2802,7 @@ class Axes(object):
|
||||
:param where: (*array_like*) If None, default to fill between everywhere. If not None, it is an
|
||||
N-length boolean array and the fill will only happen over the regions where ``where==True``.
|
||||
"""
|
||||
#Add data series
|
||||
# Add data series
|
||||
label = kwargs.pop('label', 'S_0')
|
||||
dn = len(y)
|
||||
ydata = plotutil.getplotdata(y)
|
||||
@ -2822,7 +2825,7 @@ class Axes(object):
|
||||
where = np.array(where)
|
||||
where = where.asarray()
|
||||
|
||||
#Set plot data styles
|
||||
# Set plot data styles
|
||||
# if not 'fill' in kwargs:
|
||||
# kwargs['fill'] = True
|
||||
# if not 'edge' in kwargs:
|
||||
@ -2830,7 +2833,7 @@ class Axes(object):
|
||||
pb, isunique = plotutil.getlegendbreak('polygon', **kwargs)
|
||||
pb.setCaption(label)
|
||||
|
||||
#Create graphics
|
||||
# Create graphics
|
||||
graphics = GraphicFactory.createFillBetweenPolygonsX(ydata, x1, x2, where, pb)
|
||||
zorder = kwargs.pop('zorder', None)
|
||||
self.add_graphic(graphics, zorder=zorder)
|
||||
@ -2904,7 +2907,7 @@ class Axes(object):
|
||||
jmap[key] = value
|
||||
wedgeprops = jmap
|
||||
|
||||
#Create graphics
|
||||
# Create graphics
|
||||
graphics = GraphicFactory.createPieArcs(x, colors, labels, startangle, explode, font, fontcolor, \
|
||||
labeldistance, autopct, pctdistance, radius, wedgeprops)
|
||||
|
||||
@ -2919,8 +2922,10 @@ class Axes(object):
|
||||
|
||||
return tuple(graphics)
|
||||
|
||||
def boxplot(self, x, sym=None, vert=True, positions=None, widths=None, color=None, showcaps=True, showfliers=True, showmeans=False, \
|
||||
showmedians=True, meanline=False, medianline=True, boxprops=None, medianprops=None, meanprops=None, whiskerprops=None, capprops=None, flierprops=None):
|
||||
def boxplot(self, x, sym=None, vert=True, positions=None, widths=None, color=None, showcaps=True, showfliers=True,
|
||||
showmeans=False, \
|
||||
showmedians=True, meanline=False, medianline=True, boxprops=None, medianprops=None, meanprops=None,
|
||||
whiskerprops=None, capprops=None, flierprops=None):
|
||||
"""
|
||||
Make a box and whisker plot.
|
||||
|
||||
@ -2975,7 +2980,7 @@ class Axes(object):
|
||||
elif isinstance(widths, (NDArray, DimArray)):
|
||||
widths = widths.tolist()
|
||||
|
||||
#Get box plot properties
|
||||
# Get box plot properties
|
||||
if not color is None:
|
||||
color = plotutil.getcolor(color)
|
||||
if not sym is None:
|
||||
@ -3038,13 +3043,15 @@ class Axes(object):
|
||||
flierprops.setColor(color is None and Color.red or color)
|
||||
flierprops.setStyle(PointStyle.PLUS)
|
||||
|
||||
#Create graphics
|
||||
# Create graphics
|
||||
if vert:
|
||||
graphics = GraphicFactory.createBox(x, positions, widths, showcaps, showfliers, showmeans, \
|
||||
showmedians, boxprops, medianprops, whiskerprops, capprops, meanprops, flierprops)
|
||||
showmedians, boxprops, medianprops, whiskerprops, capprops, meanprops,
|
||||
flierprops)
|
||||
else:
|
||||
graphics = GraphicFactory.createHBox(x, positions, widths, showcaps, showfliers, showmeans, \
|
||||
showmedians, boxprops, medianprops, whiskerprops, capprops, meanprops, flierprops)
|
||||
showmedians, boxprops, medianprops, whiskerprops, capprops, meanprops,
|
||||
flierprops)
|
||||
|
||||
self.add_graphic(graphics)
|
||||
self._axes.setAutoExtent()
|
||||
@ -3072,13 +3079,13 @@ class Axes(object):
|
||||
n = len(dataset)
|
||||
|
||||
if positions is None:
|
||||
positions = np.arange(1, n+1)
|
||||
positions = np.arange(1, n + 1)
|
||||
|
||||
graphics = []
|
||||
pdfs = []
|
||||
xx = []
|
||||
max = 0
|
||||
for data,position in zip(dataset, positions):
|
||||
for data, position in zip(dataset, positions):
|
||||
if data.contains_nan():
|
||||
data = np.delnan(data)
|
||||
kde = np.stats.GaussianKDE(data)
|
||||
@ -3090,20 +3097,20 @@ class Axes(object):
|
||||
max = pdf.max()
|
||||
|
||||
if boxprops is None:
|
||||
boxprops = dict(color='k',edgecolor=None)
|
||||
boxprops = dict(color='k', edgecolor=None)
|
||||
if whiskerprops is None:
|
||||
whiskerprops = whiskerprops=dict(color='k')
|
||||
whiskerprops = whiskerprops = dict(color='k')
|
||||
if not kwargs.has_key('color'):
|
||||
kwargs['color'] = 'c'
|
||||
if not kwargs.has_key('edgecolor'):
|
||||
kwargs['edgecolor'] = 'b'
|
||||
ratio = widths / max
|
||||
for data,position,pdf,x in zip(dataset, positions, pdfs, xx):
|
||||
for data, position, pdf, x in zip(dataset, positions, pdfs, xx):
|
||||
pdf = pdf * ratio
|
||||
self.fill_betweenx(x, position-pdf, position+pdf, **kwargs)
|
||||
self.fill_betweenx(x, position - pdf, position + pdf, **kwargs)
|
||||
ggs = self.boxplot(data, positions=[position], widths=boxwidth, showfliers=False, \
|
||||
showcaps=False, medianline=False, boxprops=boxprops, \
|
||||
whiskerprops=whiskerprops, medianprops=dict(color='w',edgecolor=None))
|
||||
whiskerprops=whiskerprops, medianprops=dict(color='w', edgecolor=None))
|
||||
graphics.extend(ggs)
|
||||
|
||||
return graphics
|
||||
@ -3128,18 +3135,18 @@ class Axes(object):
|
||||
|
||||
:returns: Axes and Taylor graphic.
|
||||
"""
|
||||
#Set axes
|
||||
# Set axes
|
||||
self.set_aspect('equal')
|
||||
self.set_clip(False)
|
||||
self.xaxis(location='top', visible=False)
|
||||
self.yaxis(location='right', visible=False)
|
||||
|
||||
#plot RMS circle
|
||||
# plot RMS circle
|
||||
th = np.linspace(0, np.pi, 200)
|
||||
xunit = np.cos(th)
|
||||
yunit = np.sin(th)
|
||||
tickrms = np.arange(0.25, ref_std + 0.2, 0.25)
|
||||
radius = np.sqrt(ref_std**2 + std_max**2 -
|
||||
radius = np.sqrt(ref_std ** 2 + std_max ** 2 -
|
||||
2 * ref_std * std_max * xunit)
|
||||
for iradius in tickrms:
|
||||
phi = th[np.where(radius >= iradius)]
|
||||
@ -3149,7 +3156,7 @@ class Axes(object):
|
||||
std_max * np.cos(phi))
|
||||
self.plot(xunit[ig] * iradius + ref_std, yunit[ig] * iradius, color='gray')
|
||||
|
||||
#plot stddev circle
|
||||
# plot stddev circle
|
||||
self.set_xlim(0, std_max)
|
||||
self.set_ylim(0, std_max)
|
||||
std_ticks = np.arange(0, std_max, 0.25)
|
||||
@ -3171,9 +3178,9 @@ class Axes(object):
|
||||
std_max_axis_props = kwargs.pop('std_max_axis_props', dict(color='k'))
|
||||
self.plot(xunit * std_max, yunit * std_max, **std_max_axis_props)
|
||||
|
||||
#plot correlation lines
|
||||
# plot correlation lines
|
||||
values = np.arange(0., 1., 0.1)
|
||||
values = values.join(np.array([0.95,0.99,1.0]), 0)
|
||||
values = values.join(np.array([0.95, 0.99, 1.0]), 0)
|
||||
corr_tick_props = kwargs.pop('corr_tick_props', dict(color='k'))
|
||||
corr_tick_label_props = kwargs.pop('corr_tick_label_props', dict(yalign='center'))
|
||||
if not corr_tick_label_props.has_key('yalign'):
|
||||
@ -3189,24 +3196,24 @@ class Axes(object):
|
||||
y = np.sin(theta) * std_max
|
||||
if 0 < t < 1:
|
||||
if t == 0.6 or t == 0.9:
|
||||
self.plot([0,x], [0,y], color='gray', linestyle=':')
|
||||
self.plot([x*0.98,x], [y*0.98,y], **corr_tick_props)
|
||||
self.plot([0, x], [0, y], color='gray', linestyle=':')
|
||||
self.plot([x * 0.98, x], [y * 0.98, y], **corr_tick_props)
|
||||
x = x * 1.02
|
||||
y = y * 1.02
|
||||
self.text(x, y, str(t), rotation=np.degrees(theta), **corr_tick_label_props)
|
||||
if t == 0.7:
|
||||
self.text(x*1.1, y*1.1, 'Correlation', rotation=np.degrees(theta)-90,
|
||||
self.text(x * 1.1, y * 1.1, 'Correlation', rotation=np.degrees(theta) - 90,
|
||||
**corr_label_props)
|
||||
|
||||
values = np.arange(0.05, 0.9, 0.1)
|
||||
values = values.join(np.array([0.91,0.92,0.93,0.94,0.96,0.97,0.98]), 0)
|
||||
values = values.join(np.array([0.91, 0.92, 0.93, 0.94, 0.96, 0.97, 0.98]), 0)
|
||||
for t in values:
|
||||
theta = np.acos(t)
|
||||
x = np.cos(theta) * std_max
|
||||
y = np.sin(theta) * std_max
|
||||
self.plot([x*0.99,x], [y*0.99,y], **corr_tick_props)
|
||||
self.plot([x * 0.99, x], [y * 0.99, y], **corr_tick_props)
|
||||
|
||||
#plot data
|
||||
# plot data
|
||||
stddev = np.atleast_2d(stddev)
|
||||
correlation = np.atleast_2d(correlation)
|
||||
if not labels is None:
|
||||
@ -3227,7 +3234,7 @@ class Axes(object):
|
||||
if labels is None:
|
||||
lbs = []
|
||||
for j in range(len(rho)):
|
||||
lbs.append(str(j+1))
|
||||
lbs.append(str(j + 1))
|
||||
else:
|
||||
lbs = labels[i]
|
||||
for xx, yy, label in zip(x, y, lbs):
|
||||
@ -4172,8 +4179,8 @@ class PolarAxes(Axes):
|
||||
if colors is None:
|
||||
colors = plotutil.makecolors(wsN, cmap=cmap, alpha=alpha)
|
||||
|
||||
wd = wd + 360./wdN/2
|
||||
wd[wd>360] = wd - 360
|
||||
wd = wd + 360. / wdN / 2
|
||||
wd[wd > 360] = wd - 360
|
||||
rwd = np.radians(wd)
|
||||
|
||||
width = kwargs.pop('width', 0.5)
|
||||
@ -4188,19 +4195,19 @@ class PolarAxes(Axes):
|
||||
hhist = 0
|
||||
rrmax = 0
|
||||
for i in range(wsN):
|
||||
idx = np.where((ws>=wsbins[i]) * (ws<wsbins[i+1]))
|
||||
idx = np.where((ws >= wsbins[i]) * (ws < wsbins[i + 1]))
|
||||
if idx is None:
|
||||
continue
|
||||
print(wsbins[i], wsbins[i+1])
|
||||
print(wsbins[i], wsbins[i + 1])
|
||||
s_wd = rwd[idx]
|
||||
wdhist = np.histogram(s_wd, wdbins)[0].astype('float')
|
||||
wdhist = wdhist / N
|
||||
rrmax = max(rrmax, wdhist.max())
|
||||
lab = '%s - %s' % (wsbins[i], wsbins[i+1])
|
||||
lab = '%s - %s' % (wsbins[i], wsbins[i + 1])
|
||||
bb = self.bar(theta, wdhist, width, bottom=hhist, color=colors[i], \
|
||||
edgecolor='gray', label=lab, morepoints=True)[0]
|
||||
bb.setStartValue(wsbins[i])
|
||||
bb.setEndValue(wsbins[i+1])
|
||||
bb.setEndValue(wsbins[i + 1])
|
||||
bars.append(bb)
|
||||
hhist = hhist + wdhist
|
||||
|
||||
@ -4213,11 +4220,11 @@ class PolarAxes(Axes):
|
||||
self.set_rticks(rticks)
|
||||
self.set_rtick_format('%')
|
||||
self.set_rlabel_position(rlabelpos)
|
||||
self.set_xtick_locations(np.arange(0., 360., 360./wdN))
|
||||
self.set_xtick_locations(np.arange(0., 360., 360. / wdN))
|
||||
step = 16 / nwdbins
|
||||
if xticks is None:
|
||||
xticks = ['E','ENE','NE','NNE','N','NNW','NW','WNW','W','WSW', \
|
||||
'SW','SSW','S','SSE','SE','ESE']
|
||||
xticks = ['E', 'ENE', 'NE', 'NNE', 'N', 'NNW', 'NW', 'WNW', 'W', 'WSW', \
|
||||
'SW', 'SSW', 'S', 'SSE', 'SE', 'ESE']
|
||||
xticks = xticks[::step]
|
||||
elif not xticks:
|
||||
xticks = [''] * nwdbins
|
||||
|
||||
Binary file not shown.
@ -1436,7 +1436,7 @@ class Axes3DGL(Axes3D):
|
||||
alpha_min = kwargs.pop('alpha_min', 0.1)
|
||||
alpha_max = kwargs.pop('alpha_max', 0.6)
|
||||
density = kwargs.pop('density', 2)
|
||||
graphics = JOGLUtil.particles(data.asarray(), x.asarray(), y.asarray(), z.asarray(), ls, \
|
||||
graphics = GraphicFactory.particles(data.asarray(), x.asarray(), y.asarray(), z.asarray(), ls, \
|
||||
alpha_min, alpha_max, density)
|
||||
s = kwargs.pop('s', None)
|
||||
if s is None:
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#-----------------------------------------------------
|
||||
# -----------------------------------------------------
|
||||
# Author: Yaqiang Wang
|
||||
# Date: 2017-7-27
|
||||
# Purpose: MeteoInfo plotutil module in plotlib package
|
||||
# Note: Jython
|
||||
#-----------------------------------------------------
|
||||
# -----------------------------------------------------
|
||||
|
||||
import os
|
||||
import datetime
|
||||
@ -23,6 +23,7 @@ import mipylib.numeric as np
|
||||
import mipylib.miutil as miutil
|
||||
import mipylib.migl as migl
|
||||
|
||||
|
||||
def getplotdata(data):
|
||||
if isinstance(data, NDArray):
|
||||
if data.dtype == np.dtype.date:
|
||||
@ -40,6 +41,7 @@ def getplotdata(data):
|
||||
else:
|
||||
return np.array([data])._array
|
||||
|
||||
|
||||
def getfont(fontdic, **kwargs):
|
||||
basefont = kwargs.pop('basefont', None)
|
||||
if basefont is None:
|
||||
@ -68,6 +70,7 @@ def getfont(fontdic, **kwargs):
|
||||
font = Font(name, Font.PLAIN, size)
|
||||
return font
|
||||
|
||||
|
||||
def getfont_1(**kwargs):
|
||||
fontname = kwargs.pop('fontname', 'Arial')
|
||||
fontsize = kwargs.pop('fontsize', 14)
|
||||
@ -78,6 +81,7 @@ def getfont_1(**kwargs):
|
||||
font = Font(fontname, Font.PLAIN, fontsize)
|
||||
return font
|
||||
|
||||
|
||||
def getcolor(style, alpha=None):
|
||||
if style is None:
|
||||
return None
|
||||
@ -132,6 +136,7 @@ def getcolor(style, alpha=None):
|
||||
|
||||
return c
|
||||
|
||||
|
||||
def getcolor_style(style):
|
||||
c = Color.black
|
||||
rr = None
|
||||
@ -167,6 +172,7 @@ def getcolor_style(style):
|
||||
style = style.replace(rr, '')
|
||||
return c, style
|
||||
|
||||
|
||||
def getcolors(cs, alpha=None):
|
||||
colors = []
|
||||
if isinstance(cs, (tuple, list, NDArray)):
|
||||
@ -179,6 +185,7 @@ def getcolors(cs, alpha=None):
|
||||
colors.append(getcolor(cs, alpha))
|
||||
return colors
|
||||
|
||||
|
||||
def getcolormap(**kwargs):
|
||||
colors = kwargs.pop('colors', None)
|
||||
is_single = False
|
||||
@ -218,6 +225,7 @@ def getcolormap(**kwargs):
|
||||
cmap.reverse()
|
||||
return cmap
|
||||
|
||||
|
||||
def makecolors(n, cmap='matlab_jet', reverse=False, alpha=None, start=None, stop=None):
|
||||
"""
|
||||
Make colors.
|
||||
@ -234,7 +242,7 @@ def makecolors(n, cmap='matlab_jet', reverse=False, alpha=None, start=None, stop
|
||||
if isinstance(n, list):
|
||||
cols = getcolors(n, alpha)
|
||||
else:
|
||||
#ocmap = ColorUtil.getColorMap(cmap)
|
||||
# ocmap = ColorUtil.getColorMap(cmap)
|
||||
ocmap = getcolormap(cmap=cmap)
|
||||
if reverse:
|
||||
ocmap.reverse()
|
||||
@ -256,6 +264,7 @@ def makecolors(n, cmap='matlab_jet', reverse=False, alpha=None, start=None, stop
|
||||
cols = ocmap.getColorListAlpha(n, alpha, start, stop)
|
||||
return list(cols)
|
||||
|
||||
|
||||
def getpointstyle(style):
|
||||
if style is None:
|
||||
return None
|
||||
@ -290,6 +299,7 @@ def getpointstyle(style):
|
||||
|
||||
return pointStyle
|
||||
|
||||
|
||||
def getlinestyle(style):
|
||||
if style is None:
|
||||
return None
|
||||
@ -310,6 +320,7 @@ def getlinestyle(style):
|
||||
|
||||
return lineStyle
|
||||
|
||||
|
||||
def getlinestyle_1(style):
|
||||
if style is None:
|
||||
return None
|
||||
@ -333,12 +344,14 @@ def getlinestyle_1(style):
|
||||
style = style.replace(rr, '')
|
||||
return lineStyle, style
|
||||
|
||||
|
||||
def gethatch(h):
|
||||
if h is None:
|
||||
return h
|
||||
else:
|
||||
return HatchStyle.getStyle(h)
|
||||
|
||||
|
||||
def getplotstyle(style, caption, **kwargs):
|
||||
linewidth = kwargs.pop('linewidth', 1.0)
|
||||
if style is None:
|
||||
@ -402,6 +415,7 @@ def getplotstyle(style, caption, **kwargs):
|
||||
plb.setStyle(lineStyle)
|
||||
return plb
|
||||
|
||||
|
||||
def getlegendbreak(geometry, **kwargs):
|
||||
fill = True
|
||||
color = None
|
||||
@ -544,6 +558,7 @@ def getlegendbreak(geometry, **kwargs):
|
||||
lb.setEndValue(value)
|
||||
return lb, isunique
|
||||
|
||||
|
||||
def getlegendscheme(args, min, max, **kwargs):
|
||||
ls = kwargs.pop('symbolspec', None)
|
||||
if ls is None:
|
||||
@ -568,6 +583,7 @@ def getlegendscheme(args, min, max, **kwargs):
|
||||
# lb.setOutlineColor(edgecolor)
|
||||
return ls
|
||||
|
||||
|
||||
def setlegendscheme(ls, **kwargs):
|
||||
st = ls.getShapeType()
|
||||
if st == ShapeTypes.POINT:
|
||||
@ -579,6 +595,7 @@ def setlegendscheme(ls, **kwargs):
|
||||
else:
|
||||
setlegendscheme_image(ls, **kwargs)
|
||||
|
||||
|
||||
def setlegendscheme_image(ls, **kwargs):
|
||||
cobj = kwargs.pop('color', None)
|
||||
alpha = kwargs.pop('alpha', None)
|
||||
@ -593,6 +610,7 @@ def setlegendscheme_image(ls, **kwargs):
|
||||
|
||||
return ls
|
||||
|
||||
|
||||
def setlegendscheme_point(ls, **kwargs):
|
||||
ls = ls.convertTo(ShapeTypes.POINT)
|
||||
sizes = kwargs.get('size', None)
|
||||
@ -614,6 +632,7 @@ def setlegendscheme_point(ls, **kwargs):
|
||||
|
||||
return ls
|
||||
|
||||
|
||||
def setlegendscheme_arrow(ls, **kwargs):
|
||||
"""
|
||||
Set legend scheme as arrow breaks.
|
||||
@ -642,6 +661,7 @@ def setlegendscheme_arrow(ls, **kwargs):
|
||||
|
||||
return ls
|
||||
|
||||
|
||||
def point2arrow(pb, **kwargs):
|
||||
"""
|
||||
Convert point break to arrow break.
|
||||
@ -670,6 +690,7 @@ def point2arrow(pb, **kwargs):
|
||||
|
||||
return arrowbreak
|
||||
|
||||
|
||||
def line2arrow(lb, **kwargs):
|
||||
"""
|
||||
Convert linestring break to arrow line break.
|
||||
@ -701,6 +722,7 @@ def line2arrow(lb, **kwargs):
|
||||
|
||||
return albreak
|
||||
|
||||
|
||||
def line2stream(lb, **kwargs):
|
||||
"""
|
||||
Convert linestring break to streamline break.
|
||||
@ -742,6 +764,7 @@ def line2stream(lb, **kwargs):
|
||||
|
||||
return albreak
|
||||
|
||||
|
||||
def polygon2arrow(pb, **kwargs):
|
||||
"""
|
||||
Convert polygon break to arrow polygon break.
|
||||
@ -770,6 +793,7 @@ def polygon2arrow(pb, **kwargs):
|
||||
|
||||
return arrowbreak
|
||||
|
||||
|
||||
def setlegendscheme_line(ls, **kwargs):
|
||||
ls = ls.convertTo(ShapeTypes.POLYLINE)
|
||||
size = kwargs.pop('size', None)
|
||||
@ -790,6 +814,7 @@ def setlegendscheme_line(ls, **kwargs):
|
||||
lb.setSize(size)
|
||||
return ls
|
||||
|
||||
|
||||
def setlegendscheme_polygon(ls, **kwargs):
|
||||
ls = ls.convertTo(ShapeTypes.POLYGON)
|
||||
fill = True
|
||||
@ -849,6 +874,7 @@ def setlegendscheme_polygon(ls, **kwargs):
|
||||
lb.setStyleLineWidth(hatchlinewidth)
|
||||
return ls
|
||||
|
||||
|
||||
def setpointlegendbreak(lb, **kwargs):
|
||||
if kwargs.has_key('marker'):
|
||||
marker = kwargs['marker']
|
||||
@ -908,6 +934,7 @@ def setpointlegendbreak(lb, **kwargs):
|
||||
elif kwargs.has_key('linewidth'):
|
||||
lb.setOutlineSize(kwargs['linewidth'])
|
||||
|
||||
|
||||
def text(x, y, s, **kwargs):
|
||||
"""
|
||||
Add text to the axes. Add text in string *s* to axis at location *x* , *y* , data
|
||||
@ -990,6 +1017,7 @@ def text(x, y, s, **kwargs):
|
||||
text.setCoordinates(coordinates)
|
||||
return text
|
||||
|
||||
|
||||
def makesymbolspec(geometry, *args, **kwargs):
|
||||
"""
|
||||
Make a legend.
|
||||
@ -1062,6 +1090,7 @@ def makesymbolspec(geometry, *args, **kwargs):
|
||||
|
||||
return ls
|
||||
|
||||
|
||||
def makelegend(source, **kwargs):
|
||||
"""
|
||||
Make a legend.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user