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);
Related
Recently when I tried to create a Polygon instance in Django (version 3.1) I got this error:
GEOSException at /
Error encountered checking Geometry returned from GEOS C function "GEOSGeom_createLinearRing_r".
Here's my coordinates that I'm using:
Polygon((51.558994, -0.16349), (51.552505, -0.121468), (51.527564, -0.179695), (51.527564, -0.179695))
These coordinates are just a sample.
I'm using Polygon coordinates from the leaflet, but when I try to create django.contrib.gis.geos.polygon.Polygon Instance, I get that error.
Do have any idea or approach to store received coordinate from leaflet to polygon in Django?
Polygon first and last coordinate should be identical ( linear ring )
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.
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)
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()
I am using the latest networkx on Python3 with Linux Mint 17. I am using the pcalg method (https://github.com/keiichishima/pcalg) to build directed acyclic graphs from data. I checked to be sure that the graph has edges using the number_of_edges() function.
My code looks like this:
skel_1, sep_1 = alg.estimate_skeleton(ci.ci_test_dis, Mat_1, 0.1)
dag_1 = alg.estimate_cpdag(skel_1, sep_1)
num_edge1 = dag_1.number_of_edges()
print(num_edge1)
nx.draw_networkx(dag_1, arrows=True, edge_color='b')
plt.savefig("Target1.png")
plt.close()
When I execute this code, the nodes show up, but not the edges. Is this because I did not include the pos parameter?