It would be nice to have a plot style that draws rectangular meshes according to the input data. With this plot style, it is much easier to prepare data for the following drawing.
Alternatively, we can use set pm3d map
and plot ... with pm3d
to draw a 2d mesh plot, but it is difficult to assign precise color by value
for each mesh and not to paint meshes corresponding to missing values.
It is the reason why I request this feature here to make to draw such plots easier.
plot "foo.dat" using 1:2:3:4 with rectangles ### stroke rectangle with line plot "foo.dat" using 1:2:3:4:5 with rectangles ### fill rectangle with color
The sequence of the input data for this plot style could be x1:y1:x2:y2
or x1:y1:x2:y2:value
. The rectangular mesh to be drawn is specified by (x1,y1) and (x2,y2) as diagonals and is colored by the value if it is given.
Have you looked at the new plot style
with polygons
?Thank you for the introduction to the plotting style 'with polygon'. However, it seems to be different from what I'm looking for. I'm sorry for my lack of explanation.
First, let me explain the figure I'd most like to draw. In short, it is an "unequally spaced 2D frequency distribution with unfilled meshes partially". For a simplified example, look at the attachment "image-rectangles.png". The mesh represented by diagonals (1,1)-(3,3) in the figure is assumed not to be filled because of the NaN value. The following script generates this figure.
The figure is drawn by the enumerates of the command 'set object rectangle ...'. This figure is exactly the kind of figure we want, but we need to embed a lot of 'set object rectangle ...' sentences in our script. For me, this is just a workaround to the straightforward approach because it's more like drawing of objects than plotting of data.
If we don't have any NaN value for meshes, we can plot a similar figure with the combination of 'set pm3d map corners2color c1' and 'plot ... with pm3d'.
However, as far as the plottings of this type of figure are concerned, I am dissatisfied with the following points.
1) Splot (3d plotting command) is not intuitive for drawing 2D data.
2) We need to use a parametric representation (u,v) to superimpose other 2D curves on top of the mesh diagram.
3) We have to take into account dummy data to construct the grid (see inline data in the above script).
4) We can not construct the desired grid with data containing NaN for pm3d
In particular, I have been unable to solve the problem in 4) until now. The plot style "with image" can appropriately treat the NaN values, but it is the plot style only for equally spaced mesh data.
If the plotting style 'with rectangles' in this feature request is implemented, I think it would be possible to plot "image-rectangles.png" with the following simple or 'straightforward' description.
As for the name of the new plot style, I'm concerned about whether 'with rectangles' is appropriate.
Thank you for reading the long explanation.
Your proposed input format for 'with rectangles' would be more compact than the input format for 'with polygons'. This is an advantage when the user is creating input files by hand. However from the perspective of a program or script that is creating a data file this is a small difference. In either case the description of each rectangle can be written by a single
write
orprintf
statement.Without making any decision at this time about whether it is worth implementing your proposed new style in a future gnuplot version, let me show how your plot can be created using commands accepted already by gnuplot.
This example uses 2D plot style "with filledcurves". I have attached the complete command file, but the command itself is this:
It was intended that the new plot style "with polygons" would work exactly this way in a 2D plot. The user manual says
'plot with polygons' is currently treated as 'plot with filledcurves closed'
. Unfortunately, this example shows that this statement is not correct, since the example fails if the plot command useswith polygons
instead. That is a bug and should be fixed. For now, however, you can use the filledcurves style with existing gnuplot versions 5.0, 5.2, 5.4.Last edit: Ethan Merritt 2020-08-09
Thank you for providing an example of using 'with polygons' (currently 'with filledcurves' until bug-fix). And I'm sorry I didn't discover this method on my own with your intentions fully in mind.
First of all, I'm pleased with the example you've given because many of the problems I've been having trouble with can be solved this way.
I did not expect 'with filledcurves closed' to have such a use.
Secondly, I also found a way to create the same diagram with another existing plotting style 'with boxxyerror'.
I used the 7-columns style and changed the order of the data by 'using' (see attachments). I recognized that the plotting style I proposed was mostly the same as "boxxyerror".
Now, on my "Feature Request", I'd like to focus on whether it's possible to provide a part of the functionality of 'with boxxyerror' as 'with rectangles'. The above proposal is inspired by the fact that the functionality of 'with filledcurves closed' is provided as 'with polygons'. Additionally, I wonder if it would be possible to implement it so that the sequence of data would be "x1 y1 x2 y2 value" by association with the 'set object rectangle from ... to ...'.
I've been struggling to plot the example diagram, but I couldn't have found it without your help in the last few days of correspondence. I think ordinary users like me would be very grateful for an alias to help them find a suitable plotting style for the drawing they want to do like 'polygons' <-> 'filledcurves'.
Of course, we will use "boxxyerrors" until this feature request is accepted :-)
Thanks.
You are correct that "boxxyerrors" is even closer to the proposed "rectangles" style in that each rectangle is completely described by a single line of input data. A simple implementation of "with rectangles" as described above could rearrange the four coordinates x0,y0,x1,y1 into the six coordinates x0,y0,x0,x1,y0,y1 and hand them off to the existing code for style "boxxyerrors".
Another example that exists already in gnuplot is the recently added style "with arrows" that provides the same output as "with vectors" but uses a different set of input parameters to describe it.
Gnuplot has objects of label, arrow, rectangle, circle, polygon for annotation. And the part of them (label, arrow, circle polygon) were also implemented as the primitives of plotting styles. I think the rectangle object is also eligible to be implemented as a plotting style primitive.
I have recognized that "boxxyerror" style is mostly the same as the style I propose here. But, I think the name and the order of the data is important. Indeed, 'boxxyerror' is a suitable style name for the purpose of showing the error range of the data (I noticed that it works with abbreviation "boxxy" !).
However, I think 6-columns style of 'boxxyerror' is redundunt for the more general purpose of drawing rectangles.
The first 'x' and 'y' do not make sense to specify the shape of the rectangle,
even for 'boxxyerror' style.
Here, I can now add the applications using 'with rectangles',
Thanks.
If the primary motivation is to display a mesh, as opposed to individual arbitrarily placed rectangles, then it is also worth considering a different approach. Gnuplot supports a data input format "nonuniform matrix" that exists exactly for the purpose of describing a 2D mesh with unequal spacing. It would seem logical that just as a heatmap can be drawn for a uniform matrix with the command
There could be some variant of the command or some equivalent command that produces a heatmap from a nonuniform matrix. I have not really thought this through but perhaps it would be sufficient to allow the command
Note that it internally this would not really be "with image" because the image code only works for uniform grids, but that distinction could be hidden from the user. I can see some problems, however, starting with the issue of what exactly each (x,y) coordinate means when creating the plot. Are these the center of the pixel? the lower left corner? Currently the code would most naturally treat it as the center of the pixel, but I would guess that for most data sets the "z value" represents a measurement exactly at one of the specified (x,y) coordinates, not at the midpoint between successive coordinates.
Thank you for the thought of the 'nonuniform matrix' input.
The manual says,
This format is essentially the same as the pm3d's 3-columns input.
If we represent an nonuniform mesh with precisely the right number of data points, it will look like this.
The position of '+' mark is the grid point and z in mesh is the mesh value. The x- and y-axis should have (N+1) elements, z values should have (N, N) elements.
If we were to use the "nonuniform matrix" format as is, then we would have to treat the N columns and N rows of z as dummy data. It means that the mesh value would be represented by the index of the lower-left corner point of the mesh. The inclusion of the dummy data is the same situation as in the "with steps" for 1D data. Or it could be the same as the pm3d option 'set pm3d map corners2color c1'.
If the support on nonuniform mesh with the 'image'-like style, it is excellent. The data is compact, and the "with image" already handles NaN correctly. Additionally, in the plot of such a dense mesh, the "with rectangles" style has the problem of drawing the mesh border twice.
You seem to think that there are two approaches to this "feature request".
(1) the plotting style like "image" which accepts "nonuniform matrix" data for a dense mesh.
(2) the plotting style "rectangles" for a sparse mesh
Although I think that both of these styles, if implemented, are broadly applicable plotting styles, the primary motivation is to plotting a dense mesh (approach 1) as you said.
As you say, this would be the same as using
with pm3d
. The only difference would be that it can be issued as a 2Dplot
command rather than a 3D projectionset view map; splot...
. If the projection is acceptable, then here are the commands:Your example with pm3d works correctly!
So far, I've come across three examples of the plot I didn't think could be drawn in gnuplot.
(1) "plot ... with polygons" (plot)
(2) "plot ... with boxxyerrors" (plot)
(3) "splot ... with pm3d" with "set pm3d map ..."
It's a little different from what I suggested, but I'm pleased that I was able to know how to draw the figure. I still have kind of wish the plotting style discussed here could be introduced in a future version, but I'll make sure that I can use these three methods well for my problems.
Thank you for spending your valuable time with my request.
Tested usability with real data
The method in (1) was useful enough. Although the format of the data is more cumbersome than that of (2), it is very interesting that it can be used for non-orthogonal grids as well. However, I couldn't draw the figure properly if the following three conditions are met.
a) Binary data input
b) Include NaN in the color specification
c) "set datafile missing NaN" is set
Therefore, it is necessary that (c) is not used at the same time as the plotting of the required data. If data is given in ascii format, this probrem doesn't occur.
The method (2) is the most convenient for me when I tried it on my real data. The data are compact and easy to use.
The method of (3) was also generally available. Using multiplot and setting appropreate margins, the 2D projection of pm3d can be overlaid with other 2D plots. However, when the range of x- or y-axes is out of the grid, the edge color area is not clipped and goes out of the graph (attachment).
I select the following two 'plotting styles to draw rectangle meshes".
Thanks.