I have a task, trying to draw plot where x is year and y is the value of games, released this year. Also, I have information about game platforms. So I want to draw 10 different lines of 10 different colors. I need to do it via for cycle. If I draw it without hue param - lines have different colors, but if I add it, all lines become blue.
Code is on screenshot via the link.
for platform in top10_platofrm_sales_dict:
sns.lineplot(
data=pivot_top_10
.query('platform == #platform and year_of_release !=0 '),
x='year_of_release',
y='name',
hue = 'platform'
)
plt.gcf().set_size_inches(16, 8)
Related
I am trying to write a program that can circle / mark out 5 distinct regions of interest in an image with a white background. Essentially these are 5 experimental conditions, and ultimately I would like to analyse the intensities of these conditions. 5 circles with varying flourescence levels (red)Another example, but this time with yellow
What I want to achieve is something that can circle / mark out the regions, as seen in the image below. All 5 regions marked out -- I did this manually. I have written some code using cv2, but I haven't been able to obtain desirable results.
import cv2
import numpy as np
experiment = cv2.imread('image.png')
gray = cv2.cvtColor(experiment, cv2.COLOR_BGR2GRAY)
img = cv2.medianBlur(gray, 5)
cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 120, param1 = 100, param2 = 30, minRadius = 0, maxRadius = 0)
circles = np.uint(np.around(circles))
for i in circles[0, :]:
cv2.circle(experiment, (i[0], i[1]), i[2], (0, 255, 0), 2)
cv2.imshow("Detection results", experiment)
cv2.waitKey(0)
cv2.destroyAllWindows()
My results / code output - wrong
For the yellow, only one condition is marked while the others aren't.
For red, only the second and fifth conditions are marked
How should I change my code to ensure all 5 conditions are marked, and what parameters should I change so the circle is strictly within the bounds of the liquid, and no white background is incorporated and will affect my flourescence quantification / analysis?
Additional notes:
1. All the images being analysed will have a white background and 5 distinct liquid drops, so I think HoughCircles can handle this and I don't need any fancy AI to detect the circles?
2. Ultimately I want to have this on a website where users can simply upload their experimental results and their 5 conditions can be circled, isolated and flourescence analysis done with code--- the entire process automated. That's why I don't want to use, for instance, the ROI manager in ImageJ/Fiji because that would require users to do everything manually.
I'm doing a web analytics data trying to examine the impact of emails on our traffic. The code I have for plotting is simple:
for cid in cids:
vdf = df.query('cid_short == #cid')
plt.plot(vdf['counter'],vdf['visits'], color='red', alpha=0.05)
The goal with the format is the transparency will highlight volume. The darker the region, the greater the volume in that area.
However, when I graph the plots, I see that each line is connected by the previous line, which creates weird shapes as seen in the image below.
How can I distinguish each plot programmatically (I'm dealing with 1000s of campaigns - labelled as cids).
To solve this, I identified that if there are multiple counter instances and are not grouped, then it will show the weird graph. This is important as the line chart is created based on the order of data I feed into it.
To solve this, I did the following:
for cid in cids:
vdf = df.query('cid_short == #cid').groupby(['cid_short','counter'])['visits'].sum().reset_index()
plt.plot(vdf['counter'],vdf['visits'], color='red', alpha=0.05)
In an X-Y scatter plot, I manually add text labels to data points via Point.DataLabel. Unfortunately I find that when points are crowded then it can be difficult to tell which series a label belongs to. Therefore I want to color my text labels to match the markers.
I am happy with the default markers and their colors, but unfortunately they contain MarkerForegroundColor = -1 and MarkerForegroundColorIndex = 0, no matter which series I look at. Furthermore, Application.ActivePresentation.ColorSchemes is empty. I note that point.MarkerStyle = xlMarkerStyleAutomatic.
I found that the colors correspond to the accent colors in the active Theme (only available in PowerPoint 2007 onwards):
presentation.SlideMaster.Theme.ThemeColorScheme.Colors(MsoThemeColorSchemeIndex.msoThemeAccent1 + series_i % 6);
I'm struggling with a problem when making plots with filledcurves. Between the filled areas, there seems to be a "gap". However, these artifacts do not appear on the print, but depend on the viewer and zoom-options. In Gnuplot I use the eps terminal, the eps-files look great, but the lines appear when I'm converting to pdf. The conversion it either done directly after plotting or when converting the latex-document from dvi to pdf. As most of the documents are here on the display nowadays, this is an issue. The problem also appears when I'm directly using the pdfcairo terminal in Gnuplot, so it's not caused by the conversion (tried epstopdf and ps2pdf) alone.
I attached a SCREENSHOT of a plot displayed in "acroread" (same problem in other pdf-viewers).
Has anybody an idea how to get rid of it but keeping the graphic vectorized?
I just ran into the same issue. Apparently the filling between two curves
is done as a set of polygons that do not exactly touch one another, thus
the thin white lines visible on some PDF viewers.
One way to fix the issue is to draw over these polygon boundaries. First
define min and max functions in gnuplot:
min(x, y) = x < y ? x : y
max(x, y) = x > y ? x : y
Then, assuming that column 1 of "datafile" contains your x values and
that columns 2 and 3 contain the y values of curves 2 and 3, write:
plot "datafile" using 1:2:3 with filledcurves lc rgb "gray", \
"" using 1:2:(min($2, $3)):(max($2, $3)) with yerrorbars ps 0 lt 1 \
lc rgb "gray" lw 0.5
The first plot instruction fills the spaces between the curves in gray.
The second plot instruction draws points of zero size (ps 0) at each
x value (1) on curve (2) with thin (lw 0.5), continuous (lt 1), gray
(lc rgb "gray"), vertical errorbars (yerrorbars) from the lower to
the higher of curves 2 and 3.
This covers the white lines. To get best results you may need to
experiment with the thickness of the bars (e.g., lw 0.6, lw 0.2).
This issue is fixed with gnuplot 5.2, see https://sourceforge.net/p/gnuplot/patches/749/
The actual problem was, that filled curves were previously plotted as many quadrilaterals, which leads to artifacts (white stripes) in many viewers due to antialiasing.
Since version 5.2 filled curves are rendered as single polygon, which prevents these problems (see issue linked above).
The problem is still present in Gnuplot 5.0.4 and at least the cairolatex terminal which I use to output PDFs.
I also wanted to color the area between two curves, in my case defined as functions.
When I used something like
f(x) = 2 + sin(x)
g(x) = cos(x)
plot '+' using 1:(f($1)):(g($1)) with filledcurves closed
I got the same vertical white lines as in the question.
A simple solution for curves where one is always above the other is to let Gnuplot fill the area from the upper curve to the x-axis with the desired color and then paint it over with white from the lower curve downwards:
f(x) = 2 + sin(x)
g(x) = cos(x)
plot f(x) with filledcurves x1, g(x) w filledc x1 fs lc rgb "white"
Apparently this filledcurves style (not between curves but between a curve and an axis) avoids the trapezoid artifacts.
This can be readily extended for plotting data files and multiple stacked cures like in the question. Just paint from top to bottom and finish with white for the empty area between the lowest curve and the x-axis.
For overlapping curves a construction of minimum and maximum curves like in the answer from françois-tonneau might do the trick.
If you're talking about the red and cyan bits the gap could be an illusion caused by the Red + Cyan = White on a RGB screen. Maybe there's no gap, but the border areas appear as white due to the proximity of the pixels.
Take the screenshot and blow it up so you can see the individual pixels around the perceived gap.
If this is the case, maybe selecting a different colour scheme for the adjacent colurs would get rid of the effect. I certainly can't see anything matching your description on anywhere but the red and cyan bits.
From https://groups.google.com/forum/#!topic/comp.graphics.apps.gnuplot/ivRaKpu5cJ8, it seemed to be a pure Gostscript issue.
Using the eps terminal of Gnuplot and converting the eps file to pdf with
epstopdf -nogs <file.eps> -o <file.pdf>
solved the problem on my system. From the corresponding Man page, the "-nogs" option instructs epstopdf not to use Gostscript.
I'm using Core Plot to draw graphs in my app.
I just encountered a problem:
I have dates on the X-Axis and I use a custom labeling policy.
If I only have a few records everything works fine
If I have many records all the labels are near and not useful :-(
So the question is: How can I decide which values display and which not to always have 10 labels, separated one from the other.
Divide the number of points by the number of labels you want and round up. For example, if you have 25 data points and want roughly 10 labels, label every third data point. You'll end up with 9 evenly spaced labels.