In Julia plotting with Plots, I know how to set the various attributes when using plot() (Attributes).
I want to know how to set the default attributes, so that I don't need to set them every time.
For instance, I want to change the font-family to another one, or show the minor ticks always.
I googled but I can not find the way.
This is the way:
Use the default() function like so
using Plots
default(titlefont = (20, "times"), legendfontsize = 18, guidefont = (18, :darkgreen), tickfont = (12, :orange), guide = "x", framestyle = :zerolines, yminorgrid = true)
plot([sin, cos], -2π, 2π, label = ["sin(θ)" "cos(θ)"], title = "Trigonometric Functions", xlabel = "θ", linewidth = 2, legend = :outertopleft)
Taken from the documentation here. I know the Plots.jl docs can be a bit tricky to navigate due to their size, but in this case I just typed default into the doc search box.
Note that when using the default function you don't supply the keyword args in subsequent calls to plot, unless of course you want to change away from your newly specified defaults.
Since you are asking for a way to save defaults across sessions, I will also point you to this additional tip from the installation docs:
You can override standard default values in your ~/.julia/config/startup.jl file: PLOTS_DEFAULTS = Dict(:markersize => 10, :legend => false, warn_on_unsupported = false)
So here you are defining the new defaults as a dictionary which is used as an environment variable, which allows setting defaults before loading Plots (and thus without having the default function available).
Store your defaults in a variable and overwrite whenever needed.
defs = (linestyle=:dash, linewidth=5, linecolor=:green)
plot(rand(5);defs...,linecolor=:red)
My solution is to create an empty plot with all "default" attributes and then just add necessary layers each time to this empty plot.
Related
I am in Terraform 14 and I am trying to add labels to my template file which should generate a YAML:
Template File:
labels:
${labels}
Code:
locals {
labels = merge(
var.labels,
map(
"module", basename(abspath(path.module)),
"module_version", var.module_version
)
)
prometheus_config = templatefile("${path.module}/prometheus.tmpl", {
labels = indent(8, yamlencode(local.labels))
})
When I try to add the labels indenting with 8 this outputs in the template file causing YAML errors:
Error Output:
labels:
"module": "my_module"
"module_version": "1.0"
As you can see the module_version has indent 8 which is correct but the module line is not indented.
I tried many things like moving ${labels} everywhere in the beginning, with multiple indentations but nothing seems to work.
It is for this reason that the templatefile documentation recommends using yamlencode for the entire data structure, rather than trying to concantenate bits of YAML together using just string templates. That way the yamlencode function can guarantee you a correctly-formatted result and you only have to produce a suitable data structure:
In your case, that would involve replacing the template contents with the following:
${yamlencode({
labels = labels
})}
...and then replacing the prometheus_config definition with the following:
locals {
prometheus_config = templatefile("${path.module}/prometheus.tmpl", {
labels = local.labels
})
}
Notice that the yamlencode call is now inside the template, and it covers the entire YAML document rather than just a fragment of it.
With a simple test configuration I put together with some hard-coded values for the variables you didn't show, I got the following value for local.prometheus_config:
"labels":
"module": "example"
"module_version": "1.0"
If this was a full example of the YAML you are aiming to generate then I might also consider simplifying but just inlining the yamlencode call directly inside the local value definition, and not have the separate template file at all:
locals {
prometheus_config = yamlencode({
labels = local.labels
})
}
If the real YAML is much larger or is likely to grow larger later then I'd probably still keep that templatefile call, but I just wanted to note this for completeness, since there's more than one way to get this done.
So using terraform 14 I was not able to transform lists or maps into yaml with yamlencode. Every option I tried using the suggested answer produced results with the wrong indentation. Maybe due to the many indentation levels in the file... I am not sure. So I dropped the use of yamlencode in the solution.
Solution:
I decided to use inline solution so for lists I transform then with string with join and for maps I use jsonencode so:
# var.list is a list in terraform
# local.abels is a map in terraform
thanos_config = templatefile("${path.module}/thanos.tmpl", {
urls = join(",", var.list),
labels = jsonencode(local.labels)
})
The resulting plan output is a bit ugly but it works.
This is a new question related to a previous question I asked:
holoviews can't find flexx when using a Dimension value_format callback
Thanks to downgrading my version of flexx, I am no longer getting the warning message. However, the callback function is not working. Here is the code:
%%output size=200
%%opts Curve [width=600 height=250] {+framewise}
%%opts Curve.Load.Ticket (color='red')
def xformat(x):
# update the default tick label to append an 'a'
new = x + 'a'
return(new)
kdims=hv.Dimension('Day Section', label='Week Day and Hour', value_format=xformat)
tload = hv.Curve(simple_pd,vdims=[('Max Ticket Load', 'Maxiumum Ticket Load')],kdims=kdims,group='Load',label='Ticket')
tload
When I run with the above code, I expect to see the same amount of x axis tick labels, however, each label should have an 'a' appended to the end. However, what I am seeing is no rendering of the element at all in my notebook. I have tried a number of variations of modifying the value, and the same thing happens.
Strangely, the issue appears to be the use of the variable name new in the xformat function. If I change the name of the variable it works fine. It doesn't appear as though new is a reserved work in python though, so I am not sure why its causing a problem.
Note that using the matplotlib extension does not have the same problem, only Bokeh.
At first, from the Data Render panel in icCube report, I used context.cumulativeCol(); in the Value field in order to create my cumulated graph.
Now, since the format of my data is not well suited for my application (I have values such as '4.547473508864641e-13' which I want to be formatted to 0.00), I tried to add parameters to the function :
var col = context.getColumnIndex();
var measure = context.getMeasures();
var property = "FORMATTED_VALUE";
return context.cumulativeCol(col, measure, property);
But I cannot get a proper output.
How should I do it?
You cannot use FORMATTED_VALUE to format numbers calculated on the client side, it's available on for data that comes directly from the server. So in your case you need to implement your own client-side formatting. You could use mathJS that bundled to the reporting i.e.:
return math.format(context.cumulativeCol(col), {notation: "fixed", precision: 2})
Or use any other JS formatting method like .toFixed(2)
I am starting out with Octave. I am using Octave 4.2.0 (compiled from source) on Debian.
I have found that using the qt or fltk graphics_toolkit, have default linewidth of 0.5. I want to change the default linewidth in my .octaverc file.
I have tried adding the following to my .octaverc (separately) but they both cause errors
linewidth:def.1.5000
set(gca (), "defaultlinewidth", "1.5")
How can I change the default line width of plots via the octaverc file?
It sounds like you want to set it on the root so that all plots will use it:
set(0, "defaultlinelinewidth", 1.5);
Here is the link to the relevant part of the manual.
15.3.5 Managing Default Properties
Object properties have two classes of default values, factory defaults
(the initial values) and user-defined defaults, which may override the
factory defaults.
Although default values may be set for any object, they are set in
parent objects and apply to child objects, of the specified object
type. For example, setting the default color property of line objects
to "green", for the root object, will result in all line objects
inheriting the color "green" as the default value.
set (0, "defaultlinecolor", "green");
sets the default line color for all objects. The rule for constructing
the property name to set a default value is
default + object-type + property-name
This rule can lead to some strange looking names, for example
defaultlinelinewidth" specifies the default linewidth property for
line objects.
EDIT:
Just to place emphasis on this: You've tried to set "defaultlinewidth" which is not a valid property as explained above. The property you want to set is "defaultlinelinewidth"
I'm doing a hist plot and I want some numbers shown in the plot, so I put in a text box using mathtext for the text, but I doesn't work and I can't see why.
a = [2086., 360.5, 1000.]
b = [977., 37., 498.]
c = [4512., 690., 378.]
textstr = r'$\per50=%.2f$\n$\per16=%.2f$\n$\per84=%.2f$'%(a[0],b[0],c[0])
# these are matplotlib.patch.Patch properties
props = dict(boxstyle='round', facecolor='wheat', alpha=0.75)
# place a text box in upper left in axes coords
ax.text(0.05, 0.95, textstr, transform=ax.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
At the end of my figure I'm getting this error:
matplotlib.pyparsing.ParseFatalException: Expected end of math '$'
$\per50=2086.00$\n$\per16=977.00$\n$\per84=4512.00$ (at char 0), (line:1, col:1)
I hope you can help me!
You are getting that error because the command $\per$ does not exist. Is that a latex command you defined? If you set the matplotlib parameter text.usetex=True, it is possible to set a latex preamble and define commands there, e.g.:
rc('text', usetex=True)
rc('text.latex', preamble='something')
But I don't think this can be used to define new commands (and the use of preamble is discouraged). So your best bet is to write explicitly in matplotlib whatever \per stands for.