When I call the plot() function the resulting plot always has a fixed size when it opens in my browser. I have tried to pass a layout argument to the function in many forms but it always throws an "unhandled layout type" error.
Example code:
using Plots
plotly()
data = rand(10)
plot(data, layout = [:autosize=false, :width = 500, :height = 500])
plot(data, layout = [autosize=false, width = 500, height = 500])
plot(data, layout = ["autosize"=>false, "width" => 500, "height" => 500])
Is there anyone that knows how to pass this layout argument correctly?
This can be done be specifying not a layout argument but the argument size:
plot(data, size = (width, height))
The layout argument I was referring too is used in the Plotly documentation that only applies when calling Plotly.plot, and not when you call Plots.plot with the plotly backend selected. The Plots.plot call translates its own set of arguments correctly to the selected backend.
For reference on the different usages:
http://docs.juliaplots.org/latest/attributes/
https://plot.ly/julia/setting-graph-size/
Related
I found this answer
[Octave : How to change line color and width in drawRect
how to change the color in drawRect.
When I try the same for drawArrow, I get:
h=drawArrow(0,0,3,1,1,1,1,1);
h =
scalar structure containing the fields:
body = -12.469
head = -11.925
set(h,'color','r');
error: octave_base_value::array_value():
wrong type argument 'scalar struct'
error: set: H must be a graphics handle
What I am doing wrong here? For me it looks the same.
Thanks
Karl
You really should mention that you are using the octave-forge geometry package. drawArrow returns a struct with handles for the arrow body and head (as shown by your code) so you can and have to set them separately:
pkg load geometry
h = drawArrow (0,0,3,1,1,1,1,1);
set (h.body, "color", "r")
set (h.head, "facecolor", get(h.body, "color"))
You can also set a border around the head with "edgecolor"
hAxis.title and vAxis.title options don't seem to set the axis titles for gvisScatterChart in the package googleVis.
plot(gvisScatterChart(data.frame(x = 3, y = 4), options=list(hAxis.title = 'foo')))
"foo" doesn't appear as the horizontal axis title.
You're supposed to pass options to hAxis in a dictionary-looking JSON object format:
plot(gvisScatterChart(data.frame(x = 3, y = 4), options=list(hAxis="{title:'foo'}")))
See the examples at the bottom of the help page and this under hAxis:
a JSON object. Default null. An object with members to configure various horizontal axis elements. To specify properties of this object, you can use object literal notation, as shown here:
{title: 'Hello', titleTextStyle: {color: '#FF0000'}}
I would like to add a legend to a surface plot.
I have tried, doing like this :
X=[0:0.3:2*%pi]; //example data
[x,y]=ndgrid(X,X);
z1=sin(X')*cos(X);
z2=z1/2;
z3=z1/3;
figure=scf();
surf(x,y,z1);
surf(x,y,z2);
surf(x,y,z3);
axes=figure.children(1);
axes.children(1).foreground=color(0,0,0);
axes.children(2).foreground=color(0,0,0);
axes.children(3).foreground=color(255,0,0);
axes.children(1).color_flag=0;
axes.children(2).color_flag=0;
axes.children(3).color_flag=0;
axes.children(1).color_mode=color(0,255,0);
axes.children(2).color_mode=color(0,0,255);
axes.children(3).color_mode=0;
legend(['z1','z1 divided by 2','z1 divided by 3'],opt=2,font_size=2);
I get the following error message:
!--error 10000
legend : Neither handle of type 'Polyline' can be found.
If it's not possible to do this with the basic version of Scilab, could you please advise to me some libraries Scilab permitting to do this.
Thanks for your help.
Legend not possible for surface plots
Legends is only for plot2dx graphs as stated in the documentation of legend properties:
This entity defines the parameters for legends drawn below plot2dx
graphs or created by the captions function.
Alternatives
You could simply add a title using xtitle
xtitle('z1,z1 div by2, z2 div by 3');
You could draw a box using uicontrol and style it using uicontrol_properties:
fig = gcf();
uicontrol(fig, "style", "text", ...
"string", "<html>z1<br>z1/2<br>z1/3</html>", ...
"position",[100 100 100 100], ...
"fontsize",15);
I have a chart with a DateTime axis as my horizontal and a Linear Axis for my vertical inside a Adobe Flex Line Chart. I want to use a Cartesian Data Canvas as a background element and draw custom set of background graphics mostly rectangles. When I have more than a single data point, the graphics work perfectly since they are supposed to span the width of the entire chart.
When I have only a single data point, however, I can't seem to get the rectangles to draw. Since I want my rectangles to span the entire width of the chart, I was thinking that I could get the x-coordinates from my axis, but this isn't working.
var canvasWidth:Number = chtCanvas.width;
var canvasHeight:Number = chtCanvas.height;
var minPt:Array;
var maxPt:Array;
var minPtDate:Date;
var maxPtDate:Date;
var minPtComplete:Point;
var maxPtComplete:Point;
// This works fine when there is more than 1 data point
minPt = chtCanvas.localToData(new Point(0, 0));
maxPt = chtCanvas.localToData(new Point(canvasWidth,canvasHeight));
//This does return a date object, but wont draw below
minPtDate = axisDate.minimum;
maxPtDate = axisDate.maximum;
//This returns NaN for the x
minPtComplete = chtCanvas.dataToLocal(minPtDate, axisSalary.minimum);
maxPtComplete = chtCanvas.dataToLocal(maxPtDate, axisSalary.maximum);
// Also tried this. Also returns NaN for the x value
//minPtComplete = chtCanvas.dataToLocal(axisDate.minimum, axisSalary.minumum);
//maxPtComplete = chtCanvas.dataToLocal(axisDate.maximum, axisSalary.maximum);
My actual drawing method is as follows:
// Tried this, works with points >2, does not draw with single data point
chtCanvas.drawRect(minPt[0], detail[i].MaxValue, maxPt[0], detail[i].MinValue);
//tried this, no effect with single point
//chtCanvas.drawRect(minPtDate, detail[i].MaxValue, maxPtDate, detail[i].MinValue);
// Tried this, no effect with single point
//chtCanvas.drawRect(minPtDate, minPt[1], maxPtDate, detail[i].MinValue);
// Tried this also
//chtCanvas.drawRect(minPtComplete.x, detail[i].MaxValue, maxPtComplete.x, detail[i].MinValue);
In this example, detail is an array collection of salary values and Im using the data value in the array to determine the vertical bounds of my rectangles.
I need to draw the rectangles the entire width of the chart (even when there is only a single data point). Thanks
Thanks to Heikki for his help. The following code works to use the axis values to draw on your Cartesian Data Canvas:
chtCanvas.drawRect(axisDate.minimum as Date, axisSalary.maximum, axisDate.maximum as Date, axisSalary.minimum);
Casting the values as Date really helped. The rest of the code used above is unecessary.
One thing to note, I was using a DateFormatter to format the date values from my data. What I didn't consider was that when using a DateTimeAxis, Flex will automatically add in extra dates to display on the axis. In my case, I was using a custom parse function to create MY points, but wasnt considering the points Flex was creating and also passing to my parse function (Therefore, they were not getting parsed correctly). Once I corrected this, the values laid out correctly in the case of multiple data points. I'm still having a bit of an issue with single data points and them not filling the chart entirely, but they are now drawing.
UPDATE:
Although there are signs of life, the minimum and maximum are still not drawing the entire width of the chart in some cases depending on the dataUnits and labelUnits combination.
UPDATE #2: SOLVED
Ok, so the axis does work as minimum/maximum values for the Cartesian Data Canvas but there is something important to remember. For a single point (and probably for multiple points as well, I just couldnt visually see the difference), when using a custom DateTimeAxis parse function such as what was in the Adobe Flex ASDoc tutorials:
private function axisDateParseFunction(item:String):Date
{
var inputDate:String = item;
inputDate = fmtDate.format(inputDate);
var newDate:Date = new Date();
if(inputDate)
{
var a:Array = inputDate.split('/');
newDate.fullYear = a[2];
newDate.month = a[0] - 1;
newDate.date = a[1];
newDate.hours = 0;
newDate.hoursUTC = 0;
newDate.minutes = 0;
newDate.minutesUTC = 0;
newDate.seconds = 0;
newDate.secondsUTC = 0;
newDate.milliseconds = 0;
newDate.millisecondsUTC = 0;
}
return newDate;
}
You MUST remember to set the UTC values as shown above also. Since the DateTimeAxis uses date AND time, when you create new Date objects, their time values also get set to the local system time. Remember to set those values to zero also or you will get points that dont exactly line up with your axis labels.
I want to plotting lines corresponding to the input user will give through InputText
the code snippet, example.py
region = pd.read_csv("region.csv", encoding="utf-8").set_index("plo_region")
TS_LENGTH=360
fig = figure(plot_width=700, plot_height=500, y_axis_type="log",y_range=(10**-2, 10**3))
# callback template
def callback_template(new, table, ts_length):
# whatever behavior
def callback_region(attr, old, new):
callback_template(new, region, TS_LENGTH)
# what to add line in callback function
curdoc().clear()
fig.line(x=[1,2,3], y=[1,2,3], legend="sdfds",color="black")
curdoc().add_root(hplot(inputs, fig))
textInput_region = TextInput(value="", title="region:")
textInput_region.on_change("value", callback_region)
controls = [textInput_region]
inputs = HBox(VBoxForm(controls), width=300)
# put the button and plot in a layout and add to the document
curdoc().add_root(hplot(inputs, fig))
# HOW TO SYNC THE CHANGE ON FIG TO BROWSER ??
so if the user gives "Berlin, Hamburg" in TextInput box, it will trigger the callback function and plotting two lines on the figure. Instead, if the user gives "Berlin, Hamburg, Hannover", it will plot three lines.