python – Change the order of the handles in the legend

I want to customize the captions in matplotlib.

I wish to order the labels inside the captions horizontally and also remove the handle. The color of the labels must be identical to that of the line.

Currently, I have defined the descriptor as invisible, but I am not able to change the order of the labels.

In the expectation of expert advice.

Expected production:

enter the description of the image here

What I have achieved so far is the following:

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace (0, 20, 1000)
y1 = np.sin (x)
y2 = np.cos (x)

plt.figure (figsize = (10,7))
lines =[]
lines.append (plt.plot (x, y1, -b & # 39; label = sine & # 39;)[0])
lines.append (plt.plot (x, y2, -r & # 39; label = cosine & quot;)[0])
plt.legend (loc = top left)
plt.ylim (-1.5, 2.0)
for item_legend, handle, line in the zip (plt.legend (). get_texts (), plt.gca (). get_legend (). legendHandles, lines):
plt.setp (item_legend, color = line.get_color (), size = 30)
handle.set_visible (False)

plt.show ()

exit:

enter the description of the image here

Thank you.

mvc – Handles Javascript errors in the controller

I use jstree to get a tree in my MVC application. I am showing javascript errors when something is wrong. In this case, send an alert to Javascript. Plus, I want to code better now. For this case, I had to change the public void AddFolderat public JsonResult. I hope I'm right with that.

JsonResult public AddFolder (int id, folderId string, folderName string, parent string)
{
bool publish;
int parentFolderCount = 1;

if (parent == #)
{
publish = true;

try
{
using (NpgsqlConnection con = Helper.GetNpgsqlConnection ())
{
parentFolderCount + = con.ExecuteScalar(@ "SELECT MAX (CAST (folderid AS int)) FROM folders WHERE folderid SIMILAR TO & # 39;  d + & # 39 ;;");
}
}
catch (Exception ex)
{
return Json (new {success = true, message = "Can not count folders."}, JsonRequestBehavior.AllowGet);
}
}
other
{
publish = false;
}

int period = GetLastPeriod ();
int mrNumber = 0;
string mrDate = DateTime.Now;

if (parent == #)
folderId = parentFolderCount.ToString ();
else if (parent.Contains ("_"))
mrNumber = GetLastMrNumber (point, folderId);
other
mrNumber = GetLastMrNumber (point, folderId) + 1;

try
{
using (NpgsqlConnection con = Helper.GetNpgsqlConnection ())
{
con.Execute (@ "// Insert folders with values
}
}
catch (NpgsqlException ex)
{
NpgsqlError (ex);
}
catch (Exception ex)
{
Logging.LogToFile (ex, (int?) Logger.LogLevel.Error);
return Json (new {success = false, message = "Can not load folders."}, JsonRequestBehavior.AllowGet);
}
return Json (true);
}

So, this is my method code and I think that's the right way to send something back to AJAX? I can not get into the AJAX error section, should I? And on the JS side, I do this:

$ .ajax ({
type: "POST",
url: "@ Url.Action (" AddFolder ")",
The data: {
I did,
folderId: _folderid,
folderName: _folderName,
parent: _parent
}
success: function (data) {
if (! data.success)
alert (data.message);
location.reload ();

}
error: function (errMsg) {
alert (errMsg);
}
})

Is there a better way or better way to do this? Also, I'm not happy with parentFolderCount, declaring it, make +1, and so on. I do not know, it does not seem nice to me. Is it good to have a GetNpgsqlConnection ()? It establishes the current connection and opens the connection because I have to open many connections in many controllers.

And my last question: when the file is added correctly, I have nothing to return, but the controller wants a JsonResult. So is back Json (true) correct?

Unity – How to correctly write the character logic "stick to the surface" that handles large and unexpected time deltas?

I've tried to pin down this problem: in a 2D platformer game (but this also applies to 3D games), I want the character "to stay" at the surface on which he is evolving and at the same time keep the same speed, no matter the tilt / decline of the current surface. Also, if the speed of my character is 1 unit / s and the current delta time is 0.25, I want him to travel exactly to 0.25 units, regardless of the "shape" of the surface encountered along the route.

Naively, I started with this basic logic (warning, incoming pseudo-code):

vel + = acceleration * timeDelta;
movementDelta = vel * timeDelta;

hit = raycast (pos, down);

if (hit)
{
vectorAlongSurface = hit.normal * fancyLinearAlgebra;
pos + = vectorAlongSurface.Normalized * movementDelta.Magnitude;
}
other
{
pos + = movementDelta;
}

But this is only correct if my character moves along the same normal surface for the entire frame and breaks badly enough if, during the frame, the surface has different normals along the way. This may give the impression that the speed at which the character moves is inconsistent. To give you an example:

enter the description of the image here

Although I expect responses of the type "do not do your pitch like this", I also consider the situations in which my game is likely to undergo an unexpected shift and to face an important time delta that could push the character to cross different normal the same frame.

Any advice on how to handle this would be much appreciated. I thought somehow to trace all the superficial tilt changes of the character's position to the point of "naïve raycast strikes", but that seems like quite expensive, especially if we consider that all the characters enemies should do the same. There must be a simple solution to what I do not see. Or maybe there is a way to make the inconsistency of speed in the given example less obvious / irrelevant?

Thanks guys.