Skip to content

Commit dc9b7de

Browse files
committed
Version update to 0.1.1; requires SignalTables v0.3; README improved
1 parent b8af4cc commit dc9b7de

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SignalTablesInterface_PyPlot"
22
uuid = "a24218ac-d749-4e8e-be24-21e617b5c7ba"
33
authors = ["Martin.Otter@dlr.de <Martin.Otter@dlr.de>"]
4-
version = "0.1.0"
4+
version = "0.1.1"
55

66
[deps]
77
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
@@ -20,7 +20,7 @@ Measurements = "2"
2020
MonteCarloMeasurements = "1, 0.10"
2121
PyCall = "1.93, 1.92"
2222
PyPlot = "2.10, 2.9"
23-
SignalTables = "0.2"
23+
SignalTables = "0.3"
2424
Unitful = "1"
2525
julia = "1.7"
2626

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[SignalTablesInterface_PyPlot](https://github.com/ModiaSim/SignalTablesInterface_PyPlot.jl)
44
is an interface from [SignalTables](https://github.com/ModiaSim/SignalTables.jl) to
55
[PyPlot](https://github.com/JuliaPy/PyPlot.jl) (= a
6-
Julia interface to the [Matplotlib](http://matplotlib.org/)
6+
Julia interface to [Matplotlib](http://matplotlib.org/))
77
in order to be able to perform convenient line plots in SignalTables via PyPlot.
88

99
SignalTablesInterface_PyPlot is usually not directly used, but is activated via package

src/SignalTablesInterface_PyPlot.jl

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ module SignalTablesInterface_PyPlot
22

33
# License for this file: MIT (expat)
44
# Copyright 2017-2022, DLR Institute of System Dynamics and Control
5-
5+
66
# ToDo:
7-
# MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently
8-
# reuses the earlier instance. In a future version, a new instance will always be created and returned.
7+
# MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently
8+
# reuses the earlier instance. In a future version, a new instance will always be created and returned.
99
# Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
1010
#
1111
# Description how to get rid of the warning:
12-
# https://stackoverflow.com/questions/46933824/matplotlib-adding-an-axes-using-the-same-arguments-as-a-previous-axes#
12+
# https://stackoverflow.com/questions/46933824/matplotlib-adding-an-axes-using-the-same-arguments-as-a-previous-axes#
1313
#
1414
# ax1 = subplot(..)
1515
# plot(..)
@@ -25,8 +25,8 @@ import Measurements
2525
import MonteCarloMeasurements
2626

2727
# Determine whether pmean, pmaximum, pminimum is available (MonteCarlMeasurements, version >= 1.0)
28-
const pfunctionsDefined = isdefined(MonteCarloMeasurements, :pmean)
29-
28+
const pfunctionsDefined = isdefined(MonteCarloMeasurements, :pmean)
29+
3030
using Unitful
3131

3232
import PyCall
@@ -35,12 +35,22 @@ import PyPlot
3535
export plot, showFigure, saveFigure, closeFigure, closeAllFigures
3636

3737

38-
set_matplotlib_rcParams!(args...) =
38+
set_matplotlib_rcParams!(args...) =
3939
merge!(PyCall.PyDict(PyPlot.matplotlib."rcParams"), Dict(args...))
4040

4141

4242
include("$(SignalTables.path)/src/AbstractPlotInterface.jl")
4343

44+
function setAxisLimits(x)
45+
delta = x[end] - x[1]
46+
extra = 0.02*delta
47+
xmin = x[1]-extra
48+
xmax = x[end]+extra
49+
if !isnan(xmin) && !isnan(xmax)
50+
#println("delta = $delta, xmin=$xmin, xmax=$xmax")
51+
PyPlot.xlim(xmin,xmax)
52+
end
53+
end
4454

4555
function plotOneSignal(xsig, ysig, ysigType, label, MonteCarloAsArea)
4656
xsig2 = ustrip.(xsig)
@@ -59,6 +69,7 @@ function plotOneSignal(xsig, ysig, ysigType, label, MonteCarloAsArea)
5969
ysig_max = ysig_mean + ysig_u
6070
ysig_min = ysig_mean - ysig_u
6171
PyPlot.fill_between(xsig_mean, ysig_min, ysig_max, color=rgba2)
72+
setAxisLimits(xsig_mean)
6273

6374
elseif typeof(ysig2[1]) <: MonteCarloMeasurements.StaticParticles ||
6475
typeof(ysig2[1]) <: MonteCarloMeasurements.Particles
@@ -70,7 +81,7 @@ function plotOneSignal(xsig, ysig, ysigType, label, MonteCarloAsArea)
7081
else
7182
# MonteCarloMeasurements, version < 1.0
7283
xsig_mean = MonteCarloMeasurements.mean.(xsig2)
73-
ysig_mean = MonteCarloMeasurements.mean.(ysig2)
84+
ysig_mean = MonteCarloMeasurements.mean.(ysig2)
7485
end
7586
xsig_mean = ustrip.(xsig_mean)
7687
ysig_mean = ustrip.(ysig_mean)
@@ -82,17 +93,18 @@ function plotOneSignal(xsig, ysig, ysigType, label, MonteCarloAsArea)
8293
# Plot area of uncertainty around mean value signal (use the same color, but transparent)
8394
rgba2 = (rgba[1], rgba[2], rgba[3], 0.2)
8495
if pfunctionsDefined
85-
# MonteCarlMeasurements, version >= 1.0
96+
# MonteCarlMeasurements, version >= 1.0
8697
ysig_max = MonteCarloMeasurements.pmaximum.(ysig2)
8798
ysig_min = MonteCarloMeasurements.pminimum.(ysig2)
8899
else
89100
# MonteCarloMeasurements, version < 1.0
90101
ysig_max = MonteCarloMeasurements.maximum.(ysig2)
91-
ysig_min = MonteCarloMeasurements.minimum.(ysig2)
102+
ysig_min = MonteCarloMeasurements.minimum.(ysig2)
92103
end
93104
ysig_max = ustrip.(ysig_max)
94105
ysig_min = ustrip.(ysig_min)
95106
PyPlot.fill_between(xsig_mean, ysig_min, ysig_max, color=rgba2)
107+
setAxisLimits(xsig_mean)
96108
else
97109
# Plot all particle signals (use the same color, but transparent)
98110
rgba2 = (rgba[1], rgba[2], rgba[3], 0.1)
@@ -105,6 +117,7 @@ function plotOneSignal(xsig, ysig, ysigType, label, MonteCarloAsArea)
105117
ysig3 = ustrip.(ysig3)
106118
PyPlot.plot(xsig, ysig3, color=rgba2)
107119
end
120+
setAxisLimits(xsig)
108121
end
109122

110123
else
@@ -113,11 +126,11 @@ function plotOneSignal(xsig, ysig, ysigType, label, MonteCarloAsArea)
113126
elseif typeof(xsig2[1]) <: MonteCarloMeasurements.StaticParticles ||
114127
typeof(xsig2[1]) <: MonteCarloMeasurements.Particles
115128
if pfunctionsDefined
116-
# MonteCarlMeasurements, version >= 1.0
129+
# MonteCarlMeasurements, version >= 1.0
117130
xsig2 = MonteCarloMeasurements.pmean.(xsig2)
118131
else
119-
# MonteCarlMeasurements, version < 1.0
120-
xsig2 = MonteCarloMeasurements.mean.(xsig2)
132+
# MonteCarlMeasurements, version < 1.0
133+
xsig2 = MonteCarloMeasurements.mean.(xsig2)
121134
end
122135
xsig2 = ustrip.(xsig2)
123136
end
@@ -126,6 +139,7 @@ function plotOneSignal(xsig, ysig, ysigType, label, MonteCarloAsArea)
126139
else # SignalTables.Clocked
127140
PyPlot.plot(xsig2, ysig2, ".", label=label)
128141
end
142+
setAxisLimits(xsig2)
129143
end
130144
end
131145

@@ -137,7 +151,7 @@ end
137151
Add the time series of one name (if names is one symbol/string) or with
138152
several names (if names is a tuple of symbols/strings) to the current diagram
139153
"""
140-
function addPlot(collectionOfNames::Tuple, sigTable, grid::Bool, xLabel::Bool, xAxis, prefix::AbstractString, reuse::Bool, maxLegend::Integer,
154+
function addPlot(collectionOfNames::Tuple, sigTable, grid::Bool, xLabel::Bool, xAxis, prefix::AbstractString, reuse::Bool, maxLegend::Integer,
141155
MonteCarloAsArea::Bool, figure::Int, i::Int, j::Int, nsubFigures::Int)
142156
xsigLegend = ""
143157
nLegend = 0
@@ -161,7 +175,7 @@ function addPlot(collectionOfNames::Tuple, sigTable, grid::Bool, xLabel::Bool, x
161175
if nLegend <= maxLegend
162176
PyPlot.legend()
163177
elseif nsubFigures == 1
164-
@info "plot(..): No legend in figure $figure, since curve number (= $nLegend) > maxLegend (= $maxLegend)\nCan be fixed by plot(..., maxLegend=$nLegend)"
178+
@info "plot(..): No legend in figure $figure, since curve number (= $nLegend) > maxLegend (= $maxLegend)\nCan be fixed by plot(..., maxLegend=$nLegend)"
165179
else
166180
@info "plot(..): No legend in subfigure ($i,$j) of figure $figure, since curve number (= $nLegend) > maxLegend (= $maxLegend)\nCan be fixed by plot(..., maxLegend=$nLegend)"
167181
end
@@ -191,7 +205,7 @@ function plot(sigTable, names::AbstractMatrix; heading::AbstractString="", grid:
191205

192206
PyPlot.pygui(true) # Use separate plot windows (no inline plots)
193207

194-
208+
195209
if isnothing(sigTable)
196210
@info "The call of SignalTables.plot(sigTable, ...) is ignored, since the first argument is nothing."
197211
return
@@ -209,7 +223,7 @@ function plot(sigTable, names::AbstractMatrix; heading::AbstractString="", grid:
209223
for i = 1:nrow
210224
xLabel = i == nrow
211225
for j = 1:ncol
212-
# "reuse" gives a warning
226+
# "reuse" gives a warning
213227
# MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
214228
# One can gid rid of it by the sequence
215229
# ax1 = subplot(..)

0 commit comments

Comments
 (0)