I am using the below script for plotting the chart using python:
ax = matplotlib.pyplot.scatter(dataset.x,dataset.y,s=dataset.Colorcode*30,c=pandas.Categorical(dataset.y).codes,cmap=matplotlib.pyplot.cm.Spectral)
for line in range(0,dataset.shape[0]):
matplotlib.pyplot.text(dataset.x[line],dataset.y[line],dataset.Colorcode[line],horizontalalignment='center',size='small',weight='semibold')
matplotlib.pyplot.grid()
matplotlib.pyplot.show()
A chart is plotted as below:
As you can see it's with multiple colors and I only want to plot with three colors as below:
Can you please guide me on how I can achieve this? I am new to python.
Related
In some cases, especially in scientific papers, authors add two images in one figure on each other with different colormaps. you can see an example in the below images. Can anyone guide me on how to use matplotlib to create these kinds of images?
You can create one plot area and then simply add lines graphs, barcharts, etc. etc. to the same plot area. For example:
fig, ax = plt.subplots(figsize=(15,8))
ax.plot(df_1.index, df_1['Column_Name'], linewidth=5, color='blue', label='Some_Label')
ax.legend(loc='upper right')
ax.plot(df_2.index, df_2['Column_Name'], label='Some_Label')
ax.legend(loc='upper right')
You can create graphs using matplotlib, pandas or seaborn - it just depends what you are looking to create. What I did above is create 2 line graphs on the same plotting area - but you can do the same with other types of graphs.
I have fairly basic Python knowledge but I am trying to use it to plot a radar graph. I have done this before but now my script is causing an issue.
I don't need any data to demonstrate so I won't add it, my script draws a radar plot, and plots the data but when I add variable labels for some reason it zooms in on one quadrant of the radar plot.
fig = plt.figure()
plt.clf()
ax = fig.add_subplot(1, 1, 1, projection='radar')
ax.set_varlabels(labels)
Any ideas why and how to fix this, it used to work so I think there must have been an update and maybe I need a different command? I am using Python 3.6.4 via Anaconda.
I am using plotly to show an image using fig=px.imshow(img)
I would like it to have a discret legend similar to the ones in the pie chart or the bar chart: fig2 = px.pie(df, values=df[0],names=df.index,color =df.index, color_discrete_map= h.colormap)
imshow() does not have the argument color_discret_map but maybe there could be a work-around ?
I know it is possible with matplotlib but I need plotly to do it.
I am new in python and I create pandas series in a for-loop. Each time I want to plot the series in a figure. I use ax = series.plot(title = str(i)+'.jpg') but all figures are plotted in same window. How can I plot them in different windows?
If you are using matplotlib, use
plt.figure()
for every new figure you want to plot.
You then show all figures with
plt.show()
also, you should check out what subplots does.
I'm running a script remotely on a cluster to generate a scatter plot. I wish to save the plot, but I don't want the plot to be display or a window to come up (as when you execute plt.show() ).
My saved plots are always empty. This is the code that I'm using (below). Any tips would be very helpful. Thanks!
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim([-1,maxX+1])
ax.set_ylim([0,maxY+1])
ax.set_xlabel('Comparison number (n)', fontsize=18, fontweight='bold')
ax.set_ylabel('Normalized cross correlation score', fontsize=18, fontweight='bold')
ax.scatter(xaxis,yaxis)
plt.savefig('testfig.png')
In order to use avoid showing plot windows (i.e. to do off-screen rendering) you probably want to use a different matplotlib backend.
Before any matplotlib import statements, add
import matplotlib
matplotlib.use('Agg')
and subsequent calls to matplotlib will not show any plot windows.
If your plot file shows an empty axis, then the problem lies in the plotting arguments as calling plot with empty arguments creates an empty axis.