Rounded edges for recharts line chart - svg

I am trying to create a line chart with linear curve type but with rounded corners. Something like the following
However, putting in the type as linear creates crisp edges, like the following
How do I go about smoothening the edges and the joins of the line?
Code Snippet
<Line
type='linear'
dataKey='dataKey'
stroke='#FFA500'
strokeWidth={6}
dot={false}
/>

Related

How to make LinearGradient work for 3D graph in Qt

I have a 3D graph in Qt . I have applied linear gradient to the plot but there is no effect on the plot.My code is below.Is it because of the negative values on the Y axis,Please help
QLinearGradient gr;
gr.setColotAt(0.0,Qt::black);
gr.setColorAt(0.33,Qt::blue);
gr.setColorAt(0.67,Qt::red);
gr.setColorAt(1.0,Qt::yellow);

Creating a surface plot from an Unstructured grid vtk file using Vedo

I have an unstructured grid vtk file that contains three different types of cells (Tetrahedral, Wedge and Hexahedral). This file contains multiple Scalars (8 attributes such as Pressure, Temperature e.t.c.) and a Single Vector (U,V,W) and I am trying to create a surface plot from this file for a Scalar or Vector at a time using the Vedo python wrapper for vtk. The vtk file contains a scalar or vector value for each cell, including the point coordinates.
I have read the documentation over and over, with examples here https://vtkplotter.embl.es/content/vtkplotter/index.html. These are the things that I have tried with the challenge that I am having with each method:
Method 1: Loading the file as a TetMesh
vp = Plotter()
test = load('Case_60.vtk')
vp.show(test)
This method doesn't plot Scalar Values and only shows points. No Solid Surface. Tried using a cuttertool() with it , it throws an error saying non-Tetrahedral Cell Encountered.
Method 2: Using the UGrid
ug = UGrid('Case_60.vtk')
show(ug)
This method plots as surface with a solid color. Does not seem to be picking the Scalars.
What is the proper way for me to display surface plot and display the scalar value for each cell? Is Vedo able to do what I'm trying to do?
You might need to specify which array is to be used for coloring, e.g.:
from vedo import *
ug = UGrid(datadir+'limb_ugrid.vtk')
print(ug.getArrayNames())
ug.selectCellArray('chem_0')
show(ug, axes=True)
if this doesn't work for your mesh please submit an issue here.

Python rendering 3D, 2D images within a same window

I am trying to create a simple robot simulator with 3D + 2D(bird-eye view mini-map) like the below image.
My map file is just a list of vertices for polygon and center/radius for circles (all objects are heights of 1 where z = 0).
I found that python VTK plotter makes it really easy to visualize simple object but there is a lack of documentation for the multi-view windows. I also tried open-cv but it creates a 2D image in a separate window.
What would be the easiest way to achieve a simulator like below? There would be very few objects on the map so efficiency is not my concern.
My strategy for making a 2D mini-map overlay like this is to use glWindowPos2d and glDrawPixels, and I have found it to be very successful. You'll want to turn off common OpenGL features like texturing, lighting, and the depth test. In the following example, minimap_x and minimap_y are the window coordinates of the upper-left corner of the minimap.
For example:
glDisable(GL_TEXTURE_2D)
glDisable(GL_LIGHTING)
glDisable(GL_DEPTH_TEST)
glWindowPos2d(minimap_x, window_height - (minimap_y + minimap_height))
glDrawPixels(minimap_width, minimap_height, GL_RGBA, GL_UNSIGNED_BYTE, minimap_image)
glEnable(GL_TEXTURE_2D)
glEnable(GL_LIGHTING)
glEnable(GL_DEPTH_TEST)
You'll need to provide the minimap_image data.
In my applications, I'm typically using PyGame, and so the minimap is on a PyGame Surface. Converting the Surface to raw image data usable by glDrawPixels looks like this:
minimap_image = pygame.image.tostring(minimap_surface, "RGBA", True)

Main figure legend outside of subplots

I have a number of subplots within a single figure. Each figure plots multiple lines that represent the same thing (represented by color) but in different situations (different subplots). I would like to create a legend at the base of the figure showing what the color of the line means. However, I running into a problem with getting the legend to not overlap the subplots and if I can adjust the axes, getting the legend to save.
I have tried a few different solutions with some help here but have been unable to adapt to subplots. Below is an example code that I am working with.
import numpy as np
import matplotlib.pyplot as plt
m1=1
m2=10
x=np.linspace(0,100,num=101,endpoint=True)
y1m1=m1*x**2
y2m1=m1*x**0.5
y1m2=m2*x**2
y2m2=m2*x**0.5
fig=plt.figure(figsize=(4,4))
ax1=fig.add_subplot(211)
ax1.plot(x,y1m1,'b',label=r'$x^2$')
ax1.plot(x,y2m1,'r',label=r'$\sqrt{x}$')
ax2=fig.add_subplot(212)
ax2.plot(x,y1m2,'b')
ax2.plot(x,y2m2,'r')
fig.legend(loc='lower center',ncol=2)
fig.tight_layout()
fig.savefig('examplefig.png',dpi=300)
plt.show()
My goal is to save the output to a png for a good figure.
This is one way of doing it using the suggestion provided here. The idea is to add the legend at position with respect to a given axis object. In your case, since you want to add the legend at the base, it is preferred you specify the position relative to ax2. Using ncol=2 is a matter of personal choice.
fig=plt.figure(figsize=(4,4))
ax1=fig.add_subplot(211)
l1, = ax1.plot(x,y1m1,'b')
l2, = ax1.plot(x,y2m1,'r')
ax2=fig.add_subplot(212)
ax2.plot(x,y1m2, 'b')
ax2.plot(x,y2m2, 'r')
ax2.legend(handles = [l1,l2] , labels=[r'$x^2$', r'$\sqrt{x}$'],
bbox_to_anchor=(0.7, -0.2), ncol=2)
fig.tight_layout()

GraphViz set page width

I'm using GraphViz to determine the controls location in my C# application.
But i'm not being able to give the graphViz dot generator the width of the output.
This are the paremeters of the dot file that im using
Digraph x {
autosize=false;
size="25.7,8.3!";
resolution=100;
node [shape=rect];
(edges definitions comes here)
...
But seems to have no effect on the generated plaintext file.
Am I missing something do set the page width?
Regards
I added a -> b to your example. Here's the plaintext output I get:
digraph x {
graph [autosize=false, size="25.7,8.3!", resolution=100];
node [label="\N", shape=rect];
graph [bb="0,0,54,108"];
a [pos="27,90", width=0.75, height=0.5];
b [pos="27,18", width=0.75, height=0.5];
a -> b [pos="e,27,36.104 27,71.697 27,63.983 27,54.712 27,46.112"];
}
As you can see, the size and resolution attributes are included in the output.
You may change the values of size and resolution, this won't change anything else than those attributes in the plaintext output. The positions of all nodes and edges are relative to the bounding box (bb) of the graph.
However, if you decide for example to output a png, graphviz will use this information to scale the bounding box according to your size and resolution attributes and calculate the final image size.
In this example, the resulting png will be 444 by 831 pixels (8.3 inches with a resolution of 100 dpi result in 830 pixels, the pixel on top is probably due to a rounding error).
You may find more detailed examples about size attribute and the resulting image size in this answer.

Resources